支持自动签到统计信息

This commit is contained in:
omg-xtao 2022-10-12 21:22:41 +08:00 committed by GitHub
parent 77ee577f7a
commit 6302ba72b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 10 deletions

View File

@ -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 == "关闭":

View File

@ -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)

View File

@ -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"<b>自动签到统计信息</b>\n\n总人数:<code>{len(sign_db)}</code>\n"
return text + "\n".join(f"{name}: <code>{value}</code>" 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)