mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-09 13:50:00 +08:00
refactor code
This commit is contained in:
+14
-29
@@ -7,9 +7,9 @@ from .data_source import get_epic_game
|
||||
from models.group_remind import GroupRemind
|
||||
from nonebot.adapters.cqhttp.exception import ActionFailed
|
||||
|
||||
__plugin_name__ = 'epic免费游戏提醒'
|
||||
__plugin_name__ = "epic免费游戏提醒"
|
||||
|
||||
__plugin_usage__ = '用法:发送’epic‘'
|
||||
__plugin_usage__ = "用法:发送’epic‘"
|
||||
|
||||
|
||||
epic = on_command("epic", priority=5, block=True)
|
||||
@@ -17,44 +17,29 @@ epic = on_command("epic", priority=5, block=True)
|
||||
|
||||
@epic.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
# try:
|
||||
try:
|
||||
result = await get_epic_game()
|
||||
except:
|
||||
result = '网络出错了!'
|
||||
result, code = await get_epic_game()
|
||||
await epic.send(result)
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP {event.group_id if event.message_type != 'private' else 'private'})"
|
||||
f" 获取epic免费游戏")
|
||||
# except Exception as e:
|
||||
# logger.error(f'epic 出错 e:{e}')
|
||||
# await epic.finish('网络好像炸了,再试一次?', at_sender=True)
|
||||
f" 获取epic免费游戏"
|
||||
)
|
||||
|
||||
|
||||
# epic免费游戏
|
||||
@scheduler.scheduled_job(
|
||||
'cron',
|
||||
"cron",
|
||||
hour=12,
|
||||
minute=1,
|
||||
)
|
||||
async def _():
|
||||
# try:
|
||||
bot = get_bot()
|
||||
gl = await bot.get_group_list(self_id=bot.self_id)
|
||||
gl = [g['group_id'] for g in gl]
|
||||
gl = [g["group_id"] for g in gl]
|
||||
for g in gl:
|
||||
if await GroupRemind.get_status(g, 'epic'):
|
||||
result = await get_epic_game()
|
||||
if result == '今天没有游戏可以白嫖了!':
|
||||
return
|
||||
try:
|
||||
await bot.send_group_msg(group_id=g,
|
||||
message=result)
|
||||
except ActionFailed:
|
||||
logger.error(f'{g}群 epic免费游戏推送错误')
|
||||
# except Exception as e:
|
||||
# logger.error(f'epic免费游戏推送错误 e:{e}')
|
||||
|
||||
|
||||
|
||||
|
||||
if await GroupRemind.get_status(g, "epic"):
|
||||
result, code = await get_epic_game()
|
||||
if code == 200:
|
||||
try:
|
||||
await bot.send_group_msg(group_id=g, message=result)
|
||||
except ActionFailed:
|
||||
logger.error(f"{g}群 epic免费游戏推送错误")
|
||||
|
||||
Reference in New Issue
Block a user