fix: make bind private chat link reliable

This commit is contained in:
ngfchl
2026-07-07 09:38:58 +08:00
parent a538628728
commit a5b42ac289
+11 -4
View File
@@ -17,6 +17,7 @@ EMAIL_RE = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
async def cmd_bind(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""绑定授权账号。群内引导到私聊;私聊进入等待邮箱+Token 状态。"""
user = update.effective_user
logger.info(f"🔗 收到绑定指令: user={user.id}, chat_type={update.effective_chat.type}")
existing = await get_binding(user.id)
if existing:
text = (
@@ -32,13 +33,19 @@ async def cmd_bind(update: Update, context: ContextTypes.DEFAULT_TYPE):
return
if update.effective_chat.type != "private":
bot_username = context.bot.username or (await context.bot.get_me()).username
me = await context.bot.get_me()
bot_username = me.username
url = f"https://t.me/{bot_username}?start=bind"
keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("去私聊绑定", url=url)]])
reply = await update.message.reply_text(
"🔐 为了保护 Token,请点击按钮到私聊完成绑定。",
reply_markup=keyboard,
text = (
"🔐 为了保护 Token,请到私聊完成绑定。\n\n"
f"👉 点击进入:{url}"
)
try:
reply = await update.message.reply_text(text, reply_markup=keyboard, disable_web_page_preview=True)
except Exception as e:
logger.warning(f"🔗 绑定跳转按钮发送失败,改发普通文本: {type(e).__name__}: {e}")
reply = await update.effective_chat.send_message(text, disable_web_page_preview=True)
asyncio.create_task(auto_delete(update.message, seconds=60))
asyncio.create_task(auto_delete(reply, seconds=60))
return