🎨 Return URL button when chat is private in sign function

私聊时应该返回签到URL按钮而不是callback按钮,避免重复工作
This commit is contained in:
洛水居室 2022-11-12 21:38:28 +08:00
parent 38541428b9
commit 12ca9af57b
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
2 changed files with 15 additions and 11 deletions

View File

@ -68,18 +68,21 @@ class SignSystem:
"x-rpc-seccode": f"{validate}|jordan",
}
async def gen_challenge_button(
self, uid: int, user_id: int, gt: Optional[str] = None, challenge: Optional[str] = None
async def get_challenge_button(
self, uid: int, user_id: int, gt: Optional[str] = None, challenge: Optional[str] = None,
callback: bool = True
) -> Optional[InlineKeyboardMarkup]:
if not config.pass_challenge_user_web:
return None
if gt and challenge:
if not challenge or not gt:
gt, challenge = await self.get_challenge(uid)
if not challenge or not gt:
return None
if callback:
await self.set_challenge(uid, gt, challenge)
data = f"sign|{user_id}|{uid}"
return InlineKeyboardMarkup([[InlineKeyboardButton("请尽快点我进行手动验证", callback_data=data)]])
gt, challenge = await self.get_challenge(uid)
if not challenge or not gt:
return
else:
url = f"{config.pass_challenge_user_web}?username={bot.app.bot.username}&gt={gt}&challenge={challenge}&uid={uid}"
return InlineKeyboardMarkup([[InlineKeyboardButton("请尽快点我进行手动验证", url=url)]])
@ -384,11 +387,12 @@ class Sign(Plugin, BasePlugin):
else:
await message.reply_text("未查询到您所绑定的账号信息,请先绑定账号", reply_markup=InlineKeyboardMarkup(buttons))
except NeedChallenge as exc:
button = await self.system.gen_challenge_button(
button = await self.system.get_challenge_button(
exc.uid,
user.id,
exc.gt,
exc.challenge,
not filters.ChatType.PRIVATE.filter(message)
)
reply_message = await message.reply_text(
f"UID {exc.uid} 签到失败,触发验证码风控,请尝试点击下方按钮重新签到", allow_sending_without_reply=True, reply_markup=button

View File

@ -91,7 +91,7 @@ class StartPlugin(Plugin):
try:
client = await get_genshin_client(user.id)
await message.reply_chat_action(ChatAction.TYPING)
button = await self.sign_system.gen_challenge_button(client.uid, user.id)
button = await self.sign_system.get_challenge_button(client.uid, user.id, callback=False)
if not button:
await message.reply_text("验证请求已过期。", allow_sending_without_reply=True)
return