zhenxun_bot/plugins/epic/__init__.py

46 lines
1.4 KiB
Python
Raw Normal View History

2021-05-20 19:23:32 +08:00
from nonebot import on_command
from services.log import logger
from nonebot.adapters.cqhttp import Bot, MessageEvent
from nonebot.typing import T_State
2021-06-30 19:50:55 +08:00
from utils.utils import scheduler, get_bot
2021-05-20 19:23:32 +08:00
from .data_source import get_epic_game
from models.group_remind import GroupRemind
from nonebot.adapters.cqhttp.exception import ActionFailed
2021-07-30 21:21:51 +08:00
__plugin_name__ = "epic免费游戏提醒"
2021-06-15 10:57:08 +08:00
2021-07-30 21:21:51 +08:00
__plugin_usage__ = "用法发送epic"
2021-05-20 19:23:32 +08:00
epic = on_command("epic", priority=5, block=True)
@epic.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
2021-07-30 21:21:51 +08:00
result, code = await get_epic_game()
2021-05-20 19:23:32 +08:00
await epic.send(result)
logger.info(
f"(USER {event.user_id}, GROUP {event.group_id if event.message_type != 'private' else 'private'})"
2021-07-30 21:21:51 +08:00
f" 获取epic免费游戏"
)
2021-05-20 19:23:32 +08:00
# epic免费游戏
@scheduler.scheduled_job(
2021-07-30 21:21:51 +08:00
"cron",
2021-05-20 19:23:32 +08:00
hour=12,
minute=1,
)
async def _():
bot = get_bot()
gl = await bot.get_group_list(self_id=bot.self_id)
2021-07-30 21:21:51 +08:00
gl = [g["group_id"] for g in gl]
2021-05-20 19:23:32 +08:00
for g in gl:
2021-07-30 21:21:51 +08:00
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免费游戏推送错误")