Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/mcv_rss/__init__.py
2021-08-07 11:37:17 +08:00

165 lines
7.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import asyncio
from enum import auto
import os
import traceback
import json
from core.scheduler import Scheduler
from core.logger import Logger
from core.utils import get_url
from core.loader.decorator import command
from database import BotDBUtil
def getfileversions(path):
if not os.path.exists(path):
a = open(path, 'a')
a.close()
w = open(path, 'r+')
s = w.read().split('\n')
w.close()
return s
@command('mcv_rss', autorun=True)
@command('mcv_jira_rss', autorun=True)
async def mcv_rss(bot):
print(111)
@Scheduler.scheduled_job('interval', seconds=30)
async def java_main():
print(111)
url = 'http://launchermeta.mojang.com/mc/game/version_manifest.json'
try:
version_file = os.path.abspath('./assets/mcversion.txt')
Logger.info('Checking mcv...')
verlist = getfileversions(version_file)
file = json.loads(await get_url(url))
release = file['latest']['release']
snapshot = file['latest']['snapshot']
if release not in verlist:
Logger.info(f'huh, we find {release}.')
get_target_id = BotDBUtil.Module.get_enabled_this('mcv_rss')
for x in get_target_id:
fetch = bot.fetch_target(x)
if fetch:
try:
await fetch.sendMessage('启动器已更新' + file['latest']['release'] + '正式版。')
await asyncio.sleep(0.5)
except Exception:
traceback.print_exc()
addversion = open(version_file, 'a')
addversion.write('\n' + release)
addversion.close()
verlist = getfileversions(version_file)
if snapshot not in verlist:
Logger.info(f'huh, we find {snapshot}.')
get_target_id = BotDBUtil.Module.get_enabled_this('mcv_rss')
for x in get_target_id:
fetch = bot.fetch_target(x)
if fetch:
try:
await fetch.sendMessage('启动器已更新' + file['latest']['snapshot'] + '快照。')
await asyncio.sleep(0.5)
except Exception:
traceback.print_exc()
addversion = open('./assets/mcversion.txt', 'a')
addversion.write('\n' + snapshot)
addversion.close()
Logger.info('mcv checked.')
except Exception:
traceback.print_exc()
@Scheduler.scheduled_job('interval', seconds=30)
async def java_jira():
url = 'https://bugs.mojang.com/rest/api/2/project/10400/versions'
try:
version_file = os.path.abspath('./assets/mcversion_jira.txt')
Logger.info('Checking Jira mcv...')
verlist = getfileversions(version_file)
file = json.loads(await get_url(url))
release = []
for v in file:
if not v['archived']:
release.append(v['name'])
for x in release:
if x not in verlist:
Logger.info(f'huh, we find {x}.')
get_target_id = BotDBUtil.Module.get_enabled_this('mcv_jira_rss')
for x in get_target_id:
fetch = bot.fetch_target(x)
if fetch:
try:
await fetch.sendMessage('Jira已更新Java版' + file['latest']['snapshot'] + '\nJira上的信息仅作版本号预览用不代表启动器已更新此版本')
await asyncio.sleep(0.5)
except Exception:
traceback.print_exc()
addversion = open(version_file, 'a')
addversion.write('\n' + x)
addversion.close()
Logger.info('jira mcv checked.')
except Exception:
traceback.print_exc()
@Scheduler.scheduled_job('interval', seconds=30)
async def bedrock_jira():
url = 'https://bugs.mojang.com/rest/api/2/project/10200/versions'
try:
version_file = os.path.abspath('./assets/mcversion_jira-bedrock.txt')
Logger.info('Checking Jira mcv-bedrock...')
verlist = getfileversions(version_file)
file = json.loads(await get_url(url))
release = []
for v in file:
if not v['archived']:
release.append(v['name'])
for x in release:
if x not in verlist:
Logger.info(f'huh, we find {x}.')
get_target_id = BotDBUtil.Module.get_enabled_this('mcv_jira_rss')
for x in get_target_id:
fetch = bot.fetch_target(x)
if fetch:
try:
await fetch.sendMessage('Jira已更新基岩版' + file['latest']['snapshot'] + '\nJira上的信息仅作版本号预览用不代表启动器已更新此版本')
await asyncio.sleep(0.5)
except Exception:
traceback.print_exc()
addversion = open(version_file, 'a')
addversion.write('\n' + x)
addversion.close()
Logger.info('jira mcv-bedrock checked.')
except Exception:
traceback.print_exc()
@Scheduler.scheduled_job('interval', seconds=30)
async def bedrock_dungeons():
url = 'https://bugs.mojang.com/rest/api/2/project/11901/versions'
try:
version_file = os.path.abspath('./assets/mcversion_jira-dungeons.txt')
Logger.info('Checking Jira mcv-bedrock...')
verlist = getfileversions(version_file)
file = json.loads(await get_url(url))
release = []
for v in file:
if not v['archived']:
release.append(v['name'])
for x in release:
if x not in verlist:
Logger.info(f'huh, we find {x}.')
get_target_id = BotDBUtil.Module.get_enabled_this('mcv_jira_rss')
for x in get_target_id:
fetch = bot.fetch_target(x)
if fetch:
try:
await fetch.sendMessage('Jira已更新Dungeons ' + file['latest']['snapshot'] + '\nJira上的信息仅作版本号预览用不代表商店已更新此版本')
await asyncio.sleep(0.5)
except Exception:
traceback.print_exc()
addversion = open(version_file, 'a')
addversion.write('\n' + x)
addversion.close()
Logger.info('jira mcv-dungeons checked.')
except Exception:
traceback.print_exc()