diff --git a/plugins/genshin/sign.py b/plugins/genshin/sign.py
index 660f6e5..f4e951c 100644
--- a/plugins/genshin/sign.py
+++ b/plugins/genshin/sign.py
@@ -233,6 +233,7 @@ class Sign(Plugin, BasePlugin):
if user.chat_id == chat_id:
return "自动签到已经开启过了"
user.chat_id = chat_id
+ user.status = SignStatusEnum.STATUS_SUCCESS
await self.sign_service.update(user)
return "修改自动签到通知对话成功"
elif method == "关闭":
diff --git a/plugins/jobs/sign.py b/plugins/jobs/sign.py
index e498a01..e4d90ab 100644
--- a/plugins/jobs/sign.py
+++ b/plugins/jobs/sign.py
@@ -16,6 +16,8 @@ from core.sign.models import SignStatusEnum
from core.sign.services import SignServices
from core.user import UserService
from plugins.genshin.sign import Sign
+from plugins.system.errorhandler import notice_chat_id
+from plugins.system.sign_status import SignStatus
from utils.helpers import get_genshin_client
from utils.log import logger
@@ -85,18 +87,17 @@ class SignJob(Plugin):
@job.run_daily(time=datetime.time(hour=0, minute=1, second=0), name="SignJob")
async def sign(self, context: CallbackContext):
- if context.job.name == "SignJob":
- logger.info("正在执行自动签到")
- if context.job.name == "SignAgainJob":
- logger.info("正在执行自动重签")
+ logger.info("正在执行自动签到" if context.job.name == "SignJob" else "正在执行自动重签")
sign_list = await self.sign_service.get_all()
for sign_db in sign_list:
user_id = sign_db.user_id
- if sign_db.status != SignStatusEnum.STATUS_SUCCESS:
- if sign_db.status == SignStatusEnum.TIMEOUT_ERROR:
- if context.job.name == "SignAgainJob":
- logger.info(f"用户 [{user_id}] 即将执行重签")
- else:
+ if sign_db.status in [SignStatusEnum.INVALID_COOKIES, SignStatusEnum.FORBIDDEN]:
+ continue
+ if context.job.name == "SignJob":
+ if sign_db.status not in [SignStatusEnum.STATUS_SUCCESS, SignStatusEnum.ALREADY_CLAIMED]:
+ continue
+ elif context.job.name == "SignAgainJob":
+ if sign_db.status in [SignStatusEnum.STATUS_SUCCESS, SignStatusEnum.ALREADY_CLAIMED]:
continue
try:
text = await self.single_sign(user_id)
@@ -142,6 +143,9 @@ class SignJob(Plugin):
continue
sign_db.time_updated = datetime.datetime.now()
await self.sign_service.update(sign_db)
- logger.info("执行自动签到完成")
+ logger.info("执行自动签到完成" if context.job.name == "SignJob" else "执行自动重签完成")
if context.job.name == "SignJob":
context.job_queue.run_once(self.sign, when=datetime.time(hour=0, minute=1, second=0), name="SignAgainJob")
+ elif context.job.name == "SignAgainJob":
+ text = await SignStatus.get_sign_status(self.sign_service)
+ await context.bot.send_message(notice_chat_id, text, parse_mode=ParseMode.HTML)
diff --git a/plugins/system/sign_status.py b/plugins/system/sign_status.py
new file mode 100644
index 0000000..6da5805
--- /dev/null
+++ b/plugins/system/sign_status.py
@@ -0,0 +1,31 @@
+from telegram import Update
+from telegram.ext import CommandHandler, CallbackContext
+
+from core.plugin import Plugin, handler
+from core.sign import SignServices
+from utils.decorators.admins import bot_admins_rights_check
+from utils.log import logger
+
+
+class SignStatus(Plugin):
+ def __init__(self, sign_service: SignServices = None):
+ self.sign_service = sign_service
+
+ @staticmethod
+ async def get_sign_status(sign_service: SignServices) -> str:
+ sign_db = await sign_service.get_all()
+ names = ["签到成功", "Cookie 无效", "提前签到", "触发验证码", "API异常", "请求超时", "请求失败", "通知失败"]
+ values = [0, 0, 0, 0, 0, 0, 0, 0]
+ for sign in sign_db:
+ values[sign.status.value] += 1
+ text = f"自动签到统计信息\n\n总人数:{len(sign_db)}
\n"
+ return text + "\n".join(f"{name}: {value}
" for name, value in zip(names, values))
+
+ @handler(CommandHandler, command="sign_status", block=False)
+ @bot_admins_rights_check
+ async def sign_status(self, update: Update, _: CallbackContext):
+ user = update.effective_user
+ logger.info(f"用户 {user.full_name}[{user.id}] sign_status 命令请求")
+ message = update.effective_message
+ text = await self.get_sign_status(self.sign_service)
+ await message.reply_text(text, parse_mode="html", quote=True)