From 84682e7fae43e9c2f12d93d9d18abe65ad08bc69 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 24 May 2024 22:30:26 +0800 Subject: [PATCH] :sparkles: Support refresh all history command --- plugins/admin/set_command.py | 1 + plugins/jobs/refresh_history.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/plugins/admin/set_command.py b/plugins/admin/set_command.py index e2c30ba3..36896c23 100644 --- a/plugins/admin/set_command.py +++ b/plugins/admin/set_command.py @@ -81,6 +81,7 @@ class SetCommandPlugin(Plugin): BotCommand("save_entry", "保存条目数据"), BotCommand("remove_all_entry", "删除全部条目数据"), BotCommand("sign_all", "全部账号重新签到"), + BotCommand("refresh_all_history", "全部账号刷新历史记录"), BotCommand("send_log", "发送日志"), BotCommand("update", "更新"), BotCommand("set_command", "重设命令"), diff --git a/plugins/jobs/refresh_history.py b/plugins/jobs/refresh_history.py index 2d547f2c..b3400eeb 100644 --- a/plugins/jobs/refresh_history.py +++ b/plugins/jobs/refresh_history.py @@ -13,6 +13,7 @@ from telegram.error import BadRequest, Forbidden from core.plugin import Plugin, job from core.services.history_data.services import HistoryDataAbyssServices, HistoryDataLedgerServices from gram_core.basemodel import RegionEnum +from gram_core.plugin import handler from gram_core.services.cookies import CookiesService from gram_core.services.cookies.models import CookiesStatusEnum from plugins.genshin.abyss import AbyssPlugin @@ -21,6 +22,7 @@ from plugins.tools.genshin import GenshinHelper, PlayerNotFoundError, CookiesNot from utils.log import logger if TYPE_CHECKING: + from telegram import Update from telegram.ext import ContextTypes from simnet import GenshinClient @@ -99,6 +101,15 @@ class RefreshHistoryJob(Plugin): notice_text = NOTICE_TEXT % ("旅行札记历史记录", now, uid, "旅行札记历史记录") await self.send_notice(context, user_id, notice_text) + @handler.command(command="refresh_all_history", block=False, admin=True) + async def refresh_all_history(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE"): + user = update.effective_user + logger.info("用户 %s[%s] refresh_all_history 命令请求", user.full_name, user.id) + message = update.effective_message + reply = await message.reply_text("正在执行刷新历史记录任务,请稍后...") + await self.daily_refresh_history(context) + await reply.edit_text("全部账号刷新历史记录任务完成") + @job.run_daily(time=datetime.time(hour=6, minute=1, second=0), name="RefreshHistoryJob") async def daily_refresh_history(self, context: "ContextTypes.DEFAULT_TYPE"): logger.info("正在执行每日刷新历史记录任务")