🎨 Update Verification log and reply text

This commit is contained in:
洛水居室 2022-11-17 10:16:45 +08:00
parent 03fded915a
commit 684cba06a3
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
2 changed files with 27 additions and 21 deletions

View File

@ -65,16 +65,17 @@ class VerificationPlugins(Plugin, BasePlugin):
if context.args and len(context.args) > 0: if context.args and len(context.args) > 0:
validate = context.args[0] validate = context.args[0]
_, challenge = await self.system.get_challenge(client.uid) _, challenge = await self.system.get_challenge(client.uid)
logger.info("用户 %s[%s] 请求通过认证 challenge[%s] validate[%s] ", user.full_name, user.id, challenge, validate)
if challenge: if challenge:
try: try:
await verification.verify(challenge, validate) await verification.verify(challenge, validate)
logger.success(f"用户 %s[%s] 验证成功", user.full_name, user.id) logger.success("用户 %s[%s] 验证成功", user.full_name, user.id)
await message.reply_text("验证成功") await message.reply_text("验证成功")
except ResponseException as exc: except ResponseException as exc:
logger.warning(f"用户 %s[%s] 验证失效 API返回 [%s]%s", user.full_name, user.id, exc.code, exc.message) logger.warning("用户 %s[%s] 验证失效 API返回 [%s]%s", user.full_name, user.id, exc.code, exc.message)
await message.reply_text(f"验证失败 错误信息为 [{exc.code}]{exc.message} 请稍后重试") await message.reply_text(f"验证失败 错误信息为 [{exc.code}]{exc.message}")
else: else:
logger.warning(f"用户 %s[%s] 验证失效 请求已经过期", user.full_name, user.id) logger.warning("用户 %s[%s] 验证失效 请求已经过期", user.full_name, user.id)
await message.reply_text("验证失效 请求已经过期 请稍后重试") await message.reply_text("验证失效 请求已经过期 请稍后重试")
return return
try: try:
@ -87,13 +88,13 @@ class VerificationPlugins(Plugin, BasePlugin):
return return
try: try:
data = await verification.create() data = await verification.create()
logger.success(f"用户 %s[%s] 创建验证成功", user.full_name, user.id) challenge = data["challenge"]
gt = data["gt"]
logger.success("用户 %s[%s] 创建验证成功 gt[%s] challenge[%s]", user.full_name, user.id, gt, challenge)
except ResponseException as exc: except ResponseException as exc:
logger.warning(f"用户 %s[%s] 创建验证失效 API返回 [%s]%s 请稍后重试", user.full_name, user.id, exc.code, exc.message) logger.warning("用户 %s[%s] 创建验证失效 API返回 [%s]%s", user.full_name, user.id, exc.code, exc.message)
await message.reply_text(f"创建验证失败 错误信息为 [{exc.code}]{exc.message} 请稍后重试") await message.reply_text(f"创建验证失败 错误信息为 [{exc.code}]{exc.message} 请稍后重试")
return return
challenge = data["challenge"]
gt = data["gt"]
try: try:
validate = await verification.ajax(referer="https://webstatic.mihoyo.com/", gt=gt, challenge=challenge) validate = await verification.ajax(referer="https://webstatic.mihoyo.com/", gt=gt, challenge=challenge)
if validate: if validate:

View File

@ -144,43 +144,48 @@ class StartPlugin(Plugin):
else: else:
await message.reply_text("账户正常,无需认证") await message.reply_text("账户正常,无需认证")
return return
await message.reply_text("由于官方对第三方工具限制以及账户安全的考虑,频繁使用第三方工具会导致账号被风控并要求用过验证才能进行访问。\n" await message.reply_text(
"如果出现频繁验证请求建议暂停使用本Bot在内的第三方工具查询功能。\n" "由于官方对第三方工具限制以及账户安全的考虑,频繁使用第三方工具会导致账号被风控并要求用过验证才能进行访问。\n"
"在暂停使用期间依然出现频繁认证,建议修改密码以保护账号安全。") "如果出现频繁验证请求建议暂停使用本Bot在内的第三方工具查询功能。\n"
"在暂停使用期间依然出现频繁认证,建议修改密码以保护账号安全。"
)
verification = Verification(cookies=client.cookie_manager.cookies) verification = Verification(cookies=client.cookie_manager.cookies)
if validate: if validate:
_, challenge = await self.verification_system.get_challenge(client.uid) _, challenge = await self.verification_system.get_challenge(client.uid)
if challenge: if challenge:
logger.info(
"用户 %s[%s] 请求通过认证 challenge[%s] validate[%s] ", user.full_name, user.id, challenge, validate
)
try: try:
await verification.verify(challenge, validate) await verification.verify(challenge, validate)
logger.success(f"用户 %s[%s] 验证成功", user.full_name, user.id) logger.success("用户 %s[%s] 验证成功", user.full_name, user.id)
await message.reply_text("验证成功") await message.reply_text("验证成功")
except ResponseException as exc: except ResponseException as exc:
logger.warning(f"用户 %s[%s] 验证失效 API返回 [%s]%s", user.full_name, user.id, exc.code, exc.message) logger.warning("用户 %s[%s] 验证失效 API返回 [%s]%s", user.full_name, user.id, exc.code, exc.message)
await message.reply_text(f"验证失败 错误信息为 [{exc.code}]{exc.message} 请稍后重试") await message.reply_text(f"验证失败 错误信息为 [{exc.code}]{exc.message} 请稍后重试")
else: else:
logger.warning(f"用户 %s[%s] 验证失效 请求已经过期", user.full_name, user.id) logger.warning("用户 %s[%s] 验证失效 请求已经过期", user.full_name, user.id)
await message.reply_text("验证失效 请求已经过期 请稍后重试") await message.reply_text("验证失效 请求已经过期 请稍后重试")
return return
if bot_username: if bot_username:
try: try:
data = await verification.create() data = await verification.create()
logger.success(f"用户 %s[%s] 创建验证成功", user.full_name, user.id) challenge = data["challenge"]
gt = data["gt"]
logger.success("用户 %s[%s] 创建验证成功 gt[%s] challenge[%s]", user.full_name, user.id, gt, challenge)
except ResponseException as exc: except ResponseException as exc:
logger.warning(f"用户 %s[%s] 创建验证失效 API返回 [%s]%s", user.full_name, user.id, exc.code, exc.message) logger.warning("用户 %s[%s] 创建验证失效 API返回 [%s]%s", user.full_name, user.id, exc.code, exc.message)
await message.reply_text(f"创建验证失败 错误信息为 [{exc.code}]{exc.message} 请稍后重试") await message.reply_text(f"验证失败 错误信息为 [{exc.code}]{exc.message}")
return return
challenge = data["challenge"]
gt = data["gt"]
try: try:
validate = await verification.ajax(referer="https://webstatic.mihoyo.com/", gt=gt, challenge=challenge) validate = await verification.ajax(referer="https://webstatic.mihoyo.com/", gt=gt, challenge=challenge)
if validate: if validate:
await verification.verify(challenge, validate) await verification.verify(challenge, validate)
logger.success(f"用户 %s[%s] 通过 ajax 验证", user.full_name, user.id) logger.success("用户 %s[%s] 通过 ajax 验证", user.full_name, user.id)
await message.reply_text("验证成功") await message.reply_text("验证成功")
return return
except APIHelperException as exc: except APIHelperException as exc:
logger.warning(f"用户 %s[%s] ajax 验证失效 错误信息为 %s", user.full_name, user.id, repr(exc)) logger.warning("用户 %s[%s] ajax 验证失效 错误信息为 %s", user.full_name, user.id, repr(exc))
await self.verification_system.set_challenge(client.uid, gt, challenge) await self.verification_system.set_challenge(client.uid, gt, challenge)
url = f"{config.pass_challenge_user_web}?username={bot_username}&command=verify&gt={gt}&challenge={challenge}&uid={client.uid}" url = f"{config.pass_challenge_user_web}?username={bot_username}&command=verify&gt={gt}&challenge={challenge}&uid={client.uid}"
button = InlineKeyboardMarkup([[InlineKeyboardButton("验证", url=url)]]) button = InlineKeyboardMarkup([[InlineKeyboardButton("验证", url=url)]])