2020-08-19 04:41:47 +00:00
|
|
|
import asyncio
|
|
|
|
import traceback
|
2020-07-27 15:00:01 +00:00
|
|
|
|
2020-08-19 04:41:47 +00:00
|
|
|
from graia.application import GraiaMiraiApplication, Session
|
|
|
|
from graia.application.message.chain import MessageChain
|
|
|
|
from graia.application.message.elements.internal import Plain
|
|
|
|
from graia.broadcast import Broadcast
|
2020-08-12 16:01:34 +00:00
|
|
|
|
2020-08-19 04:41:47 +00:00
|
|
|
loop = asyncio.get_event_loop()
|
2020-08-12 16:01:34 +00:00
|
|
|
|
2020-08-19 04:41:47 +00:00
|
|
|
bcc = Broadcast(loop=loop, debug_flag=True)
|
|
|
|
app = GraiaMiraiApplication(
|
|
|
|
broadcast=bcc,
|
2020-08-30 09:34:23 +00:00
|
|
|
enable_chat_log=False,
|
2020-08-19 04:41:47 +00:00
|
|
|
connect_info=Session(
|
|
|
|
host="http://localhost:11919", # 填入 httpapi 服务运行的地址
|
|
|
|
authKey='1145141919810', # 填入 authKey
|
2020-09-05 13:25:24 +00:00
|
|
|
account=2926887640, # 你的机器人的 qq 号
|
2020-08-19 04:41:47 +00:00
|
|
|
websocket=True # Graia 已经可以根据所配置的消息接收的方式来保证消息接收部分的正常运作.
|
|
|
|
)
|
|
|
|
)
|
|
|
|
import aiohttp
|
|
|
|
async def get_data(url: str, fmt: str):
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
async with session.get(url, timeout=aiohttp.ClientTimeout(total=20)) as req:
|
|
|
|
if hasattr(req, fmt):
|
|
|
|
return await getattr(req, fmt)()
|
|
|
|
else:
|
|
|
|
raise ValueError(f"NoSuchMethod: {fmt}")
|
2020-08-12 16:01:34 +00:00
|
|
|
|
2020-08-19 04:41:47 +00:00
|
|
|
@bcc.receiver("ApplicationLaunched")
|
|
|
|
async def ver(app: GraiaMiraiApplication):
|
2020-08-18 13:12:38 +00:00
|
|
|
from modules.mcvrss import mcvrss
|
2020-07-30 14:44:17 +00:00
|
|
|
for qqgroup in mcvrss():
|
|
|
|
try:
|
2020-08-19 04:41:47 +00:00
|
|
|
await app.sendGroupMessage(int(qqgroup), MessageChain.create([Plain('已开启检测游戏版本。')]).asSendable())
|
2020-07-30 14:44:17 +00:00
|
|
|
except Exception as e:
|
2020-08-19 04:41:47 +00:00
|
|
|
traceback.print_exc()
|
2020-07-30 14:44:17 +00:00
|
|
|
print(str(e))
|
|
|
|
|
2020-07-27 15:00:01 +00:00
|
|
|
from mcversion import mcversion
|
|
|
|
import time
|
|
|
|
url = 'http://launchermeta.mojang.com/mc/game/version_manifest.json'
|
|
|
|
while True:
|
2020-07-27 15:14:33 +00:00
|
|
|
try:
|
|
|
|
verlist = mcversion()
|
2020-08-19 04:41:47 +00:00
|
|
|
file = await get_data(url,'json')
|
2020-07-27 15:14:33 +00:00
|
|
|
release = file['latest']['release']
|
|
|
|
snapshot = file['latest']['snapshot']
|
|
|
|
if release in verlist:
|
|
|
|
pass
|
|
|
|
else:
|
2020-07-30 14:44:17 +00:00
|
|
|
for qqgroup in mcvrss():
|
|
|
|
try:
|
2020-08-19 04:41:47 +00:00
|
|
|
await app.sendGroupMessage(int(qqgroup), MessageChain.create([Plain('启动器已更新' + file['latest']['release'] + '正式版。')]).asSendable())
|
2020-07-30 14:44:17 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
2020-08-12 16:01:34 +00:00
|
|
|
addversion = open('mcversion.txt', 'a')
|
|
|
|
addversion.write('\n' + release)
|
2020-07-27 15:14:33 +00:00
|
|
|
addversion.close()
|
|
|
|
if snapshot in verlist:
|
|
|
|
pass
|
|
|
|
else:
|
2020-07-30 14:44:17 +00:00
|
|
|
for qqgroup in mcvrss():
|
|
|
|
try:
|
2020-08-19 04:41:47 +00:00
|
|
|
await app.sendGroupMessage(int(qqgroup), MessageChain.create([Plain('启动器已更新' + file['latest']['snapshot'] + '快照。')]).asSendable())
|
2020-07-30 14:44:17 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
2020-08-12 16:01:34 +00:00
|
|
|
addversion = open('mcversion.txt', 'a')
|
|
|
|
addversion.write('\n' + snapshot)
|
2020-07-27 15:14:33 +00:00
|
|
|
addversion.close()
|
2020-07-30 14:44:17 +00:00
|
|
|
print('ping')
|
2020-07-27 15:14:33 +00:00
|
|
|
time.sleep(10)
|
|
|
|
except Exception as e:
|
|
|
|
print(str(e))
|
2020-07-27 15:15:06 +00:00
|
|
|
time.sleep(5)
|
2020-08-12 16:01:34 +00:00
|
|
|
|
|
|
|
|
2020-07-27 15:04:18 +00:00
|
|
|
if __name__ == "__main__":
|
2020-08-19 04:41:47 +00:00
|
|
|
app.launch_blocking()
|