mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-25 18:04:10 +00:00
🎨 Update log output and exception handler in validation
This commit is contained in:
parent
56515a2f9f
commit
ffbb224644
@ -12,10 +12,12 @@ from core.cookies.error import CookiesNotFoundError
|
||||
from core.plugin import Plugin, handler
|
||||
from core.user import UserService
|
||||
from core.user.error import UserNotFoundError
|
||||
from modules.apihelper.error import ResponseException, APIHelperException
|
||||
from modules.apihelper.hyperion import Verification
|
||||
from utils.decorators.error import error_callable
|
||||
from utils.decorators.restricts import restricts
|
||||
from utils.helpers import get_genshin_client
|
||||
from utils.log import logger
|
||||
|
||||
|
||||
class VerificationSystem:
|
||||
@ -47,6 +49,7 @@ class VerificationPlugins(Plugin, BasePlugin):
|
||||
async def verify(self, update: Update, context: CallbackContext) -> None:
|
||||
user = update.effective_user
|
||||
message = update.effective_message
|
||||
logger.info(f"用户 %s[%s] 发出verify命令", user.full_name, user.id)
|
||||
try:
|
||||
client = await get_genshin_client(user.id)
|
||||
if client.region != Region.CHINESE:
|
||||
@ -63,10 +66,16 @@ class VerificationPlugins(Plugin, BasePlugin):
|
||||
validate = context.args[0]
|
||||
_, challenge = await self.system.get_challenge(client.uid)
|
||||
if challenge:
|
||||
try:
|
||||
await verification.verify(challenge, validate)
|
||||
logger.success(f"用户 %s[%s] 验证成功", user.full_name, user.id)
|
||||
await message.reply_text("验证成功")
|
||||
except ResponseException as exc:
|
||||
logger.warning(f"用户 %s[%s] 验证失效 API返回 [%s]%s", user.full_name, user.id, exc.code, exc.message)
|
||||
await message.reply_text(f"验证失败 错误信息为 [{exc.code}]{exc.message} 请稍后重试")
|
||||
else:
|
||||
await message.reply_text("验证失效")
|
||||
logger.warning(f"用户 %s[%s] 验证失效 请求已经过期", user.full_name, user.id)
|
||||
await message.reply_text("验证失效 请求已经过期 请稍后重试")
|
||||
return
|
||||
try:
|
||||
await client.get_genshin_notes()
|
||||
@ -76,14 +85,24 @@ class VerificationPlugins(Plugin, BasePlugin):
|
||||
else:
|
||||
await message.reply_text("账户正常,无需认证")
|
||||
return
|
||||
try:
|
||||
data = await verification.create()
|
||||
logger.success(f"用户 %s[%s] 创建验证成功", user.full_name, user.id)
|
||||
except ResponseException as exc:
|
||||
logger.warning(f"用户 %s[%s] 创建验证失效 API返回 [%s]%s 请稍后重试", user.full_name, user.id, exc.code, exc.message)
|
||||
await message.reply_text(f"创建验证失败 错误信息为 [{exc.code}]{exc.message} 请稍后重试")
|
||||
return
|
||||
challenge = data["challenge"]
|
||||
gt = data["gt"]
|
||||
try:
|
||||
validate = await verification.ajax(referer="https://webstatic.mihoyo.com/", gt=gt, challenge=challenge)
|
||||
if validate:
|
||||
await verification.verify(challenge, validate)
|
||||
logger.success(f"用户 %s[%s] 通过 ajax 验证", user.full_name, user.id)
|
||||
await message.reply_text("验证成功")
|
||||
return
|
||||
except APIHelperException as exc:
|
||||
logger.warning(f"用户 %s[%s] ajax 验证失效 错误信息为 %s", user.full_name, user.id, repr(exc))
|
||||
await self.system.set_challenge(client.uid, gt, challenge)
|
||||
url = f"{config.pass_challenge_user_web}?username={context.bot.username}&command=verify>={gt}&challenge={challenge}&uid={client.uid}"
|
||||
button = InlineKeyboardMarkup([[InlineKeyboardButton("验证", url=url)]])
|
||||
|
@ -13,6 +13,7 @@ from core.cookies.error import CookiesNotFoundError
|
||||
from core.plugin import handler, Plugin
|
||||
from core.user import UserService
|
||||
from core.user.error import UserNotFoundError
|
||||
from modules.apihelper.error import ResponseException, APIHelperException
|
||||
from modules.apihelper.hyperion import Verification
|
||||
from plugins.genshin.sign import SignSystem, NeedChallenge
|
||||
from plugins.genshin.verification import VerificationSystem
|
||||
@ -53,20 +54,25 @@ class StartPlugin(Plugin):
|
||||
f"{escape_markdown('发送 /setuid 或 /setcookie 命令进入绑定账号流程')}"
|
||||
)
|
||||
elif args[0] == "verify_verification":
|
||||
logger.info(f"用户 %s[%s] 通过start命令 获取认证信息", user.full_name, user.id)
|
||||
await self.process_validate(message, user, bot_username=context.bot.username)
|
||||
elif args[0] == "sign":
|
||||
logger.info(f"用户 %s[%s] 通过start命令 获取签到信息", user.full_name, user.id)
|
||||
await self.gen_sign_button(message, user)
|
||||
elif args[0].startswith("challenge_"):
|
||||
_data = args[0].split("_")
|
||||
_command = _data[1]
|
||||
_challenge = _data[2]
|
||||
if _command == "sign":
|
||||
logger.info(f"用户 %s[%s] 通过start命令 进入签到流程", user.full_name, user.id)
|
||||
await self.process_sign_validate(message, user, _challenge)
|
||||
elif _command == "verify":
|
||||
logger.info(f"用户 %s[%s] 通过start命令 进入认证流程", user.full_name, user.id)
|
||||
await self.process_validate(message, user, validate=_challenge)
|
||||
else:
|
||||
await message.reply_html(f"你好 {user.mention_html()} !我是派蒙 !\n请点击 /{args[0]} 命令进入对应流程")
|
||||
return
|
||||
logger.info(f"用户 %s[%s] 发出start命令", user.full_name, user.id)
|
||||
await message.reply_markdown_v2(f"你好 {user.mention_markdown_v2()} {escape_markdown('!我是派蒙 !')}")
|
||||
|
||||
@staticmethod
|
||||
@ -142,19 +148,36 @@ class StartPlugin(Plugin):
|
||||
if validate:
|
||||
_, challenge = await self.verification_system.get_challenge(client.uid)
|
||||
if challenge:
|
||||
try:
|
||||
await verification.verify(challenge, validate)
|
||||
logger.success(f"用户 %s[%s] 验证成功", user.full_name, user.id)
|
||||
await message.reply_text("验证成功")
|
||||
except ResponseException as exc:
|
||||
logger.warning(f"用户 %s[%s] 验证失效 API返回 [%s]%s", user.full_name, user.id, exc.code, exc.message)
|
||||
await message.reply_text(f"验证失败 错误信息为 [{exc.code}]{exc.message} 请稍后重试")
|
||||
else:
|
||||
await message.reply_text("验证失效")
|
||||
logger.warning(f"用户 %s[%s] 验证失效 请求已经过期", user.full_name, user.id)
|
||||
await message.reply_text("验证失效 请求已经过期 请稍后重试")
|
||||
return
|
||||
if bot_username:
|
||||
try:
|
||||
data = await verification.create()
|
||||
logger.success(f"用户 %s[%s] 创建验证成功", user.full_name, user.id)
|
||||
except ResponseException as exc:
|
||||
logger.warning(f"用户 %s[%s] 创建验证失效 API返回 [%s]%s", user.full_name, user.id, exc.code, exc.message)
|
||||
await message.reply_text(f"创建验证失败 错误信息为 [{exc.code}]{exc.message} 请稍后重试")
|
||||
return
|
||||
challenge = data["challenge"]
|
||||
gt = data["gt"]
|
||||
try:
|
||||
validate = await verification.ajax(referer="https://webstatic.mihoyo.com/", gt=gt, challenge=challenge)
|
||||
if validate:
|
||||
await verification.verify(challenge, validate)
|
||||
logger.success(f"用户 %s[%s] 通过 ajax 验证", user.full_name, user.id)
|
||||
await message.reply_text("验证成功")
|
||||
return
|
||||
except APIHelperException as exc:
|
||||
logger.warning(f"用户 %s[%s] ajax 验证失效 错误信息为 %s", user.full_name, user.id, repr(exc))
|
||||
await self.sign_system.set_challenge(client.uid, gt, challenge)
|
||||
url = f"{config.pass_challenge_user_web}?username={bot_username}&command=verify>={gt}&challenge={challenge}&uid={client.uid}"
|
||||
button = InlineKeyboardMarkup([[InlineKeyboardButton("验证", url=url)]])
|
||||
|
Loading…
Reference in New Issue
Block a user