2022-06-12 07:07:53 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from config import Config
|
2023-02-05 14:33:33 +00:00
|
|
|
from core.builtins import Bot, Image
|
2023-03-04 08:51:56 +00:00
|
|
|
from core.component import module
|
2022-04-17 15:58:30 +00:00
|
|
|
from .daily_trials import fetch_daily_trials, json_render
|
|
|
|
|
2023-03-04 08:51:56 +00:00
|
|
|
dun = module('dungeons_trials', alias=['dungeons', 'dungeon', 'dungeonstrials', 'dungeontrials', 'dungeon_trials'],
|
2023-04-30 03:30:59 +00:00
|
|
|
desc='获取Minecraft Dungeons每日挑战信息。缓存12小时重置一次。')
|
2022-04-17 15:58:30 +00:00
|
|
|
|
|
|
|
records = {'ts': 0}
|
|
|
|
|
|
|
|
|
|
|
|
@dun.handle()
|
2023-02-05 14:33:33 +00:00
|
|
|
async def _(msg: Bot.MessageSession):
|
2022-04-17 15:58:30 +00:00
|
|
|
await msg.sendMessage('请稍等...')
|
|
|
|
if datetime.now().timestamp() - records['ts'] > 43200:
|
|
|
|
records['data'] = await fetch_daily_trials(Config('xbox_gametag'), Config('xbox_token'))
|
|
|
|
if not records['data']:
|
|
|
|
await msg.sendMessage('获取失败。')
|
|
|
|
return
|
2022-04-17 16:20:57 +00:00
|
|
|
else:
|
|
|
|
records['ts'] = int(datetime.now().timestamp())
|
2022-04-17 15:58:30 +00:00
|
|
|
|
|
|
|
if 'data' in records:
|
|
|
|
i = []
|
|
|
|
for x in records['data']['trials']:
|
|
|
|
i.append(Image(await json_render(x)))
|
|
|
|
await msg.sendMessage(i)
|
|
|
|
|
|
|
|
|
|
|
|
@dun.handle('reset {强制重置缓存。}')
|
2023-02-05 14:33:33 +00:00
|
|
|
async def _(msg: Bot.MessageSession):
|
2022-04-17 15:58:30 +00:00
|
|
|
records['ts'] = 0
|
|
|
|
await msg.sendMessage('重置成功。')
|
|
|
|
|
|
|
|
"""qc = BotDBUtil.CoolDown(msg, 'dungeons_trials_reset')
|
|
|
|
c = qc.check(86400)
|
|
|
|
if c == 0:
|
|
|
|
qc.reset()
|
|
|
|
else:
|
|
|
|
await msg.sendMessage(f'距离上次执行已过去{int(c)}秒,本命令的冷却时间为一天。')"""
|