zhenxun_bot/plugins/epic/__init__.py

61 lines
1.8 KiB
Python
Raw Normal View History

2021-05-20 19:23:32 +08:00
from nonebot import on_command
from services.log import logger
2021-08-17 23:17:08 +08:00
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
2021-05-20 19:23:32 +08:00
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
2021-10-03 14:24:07 +08:00
from utils.manager import group_manager
__zx_plugin_name__ = "epic免费游戏"
__plugin_usage__ = """
usage
可以不玩不能没有每日白嫖
指令
epic
""".strip()
__plugin_des__ = "可以不玩,不能没有,每日白嫖"
__plugin_cmd__ = ["epic"]
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_settings__ = {
"level": 5,
"default_status": True,
"limit_superuser": False,
"cmd": ["epic"],
}
__plugin_task__ = {
'epic_free_game': '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(
2021-08-17 23:17:08 +08:00
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) 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()
2021-10-03 14:24:07 +08:00
gl = await bot.get_group_list()
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-10-03 14:24:07 +08:00
if await group_manager.check_group_task_status(g, 'epic_free_game'):
try:
result, code = await get_epic_game()
if code == 200:
2021-07-30 21:21:51 +08:00
await bot.send_group_msg(group_id=g, message=result)
2021-10-03 14:24:07 +08:00
except Exception as e:
logger.error(f"GROUP {g} epic免费游戏推送错误 {type(e)}: {e}")