🎨 全部重签添加随机延迟

This commit is contained in:
洛水居室 2022-10-16 00:11:46 +08:00
parent 247606fbb9
commit 9f2fc56ea5
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -1,5 +1,6 @@
import asyncio
import datetime
import secrets
from aiohttp import ClientConnectorError
from genshin import InvalidCookies, AlreadyClaimed, GenshinException
@ -28,6 +29,7 @@ class SignAll(Plugin):
self.sign_service = sign_service
self.cookies_service = cookies_service
self.user_service = user_service
self.random = secrets.SystemRandom()
@handler(CommandHandler, command="sign_all", block=False)
@bot_admins_rights_check
@ -66,7 +68,7 @@ class SignAll(Plugin):
try:
if "今天旅行者已经签到过了~" not in text:
await context.bot.send_message(sign_db.chat_id, text, parse_mode=ParseMode.HTML)
await asyncio.sleep(5) # 回复延迟5S避免触发洪水防御
await asyncio.sleep(10 + self.random.random() * 50) # 回复延迟 [10, 60) 避免触发洪水防御
except BadRequest as exc:
logger.error(f"执行自动签到时发生错误 用户UID[{user_id}]")
logger.exception(exc)