feat: improve telegram networking and add me command

This commit is contained in:
ngfchl
2026-07-07 10:19:24 +08:00
parent 52ee83a235
commit 13da0f358a
2 changed files with 44 additions and 1 deletions
+26
View File
@@ -107,6 +107,31 @@ async def handle_private_bind_text(update: Update, context: ContextTypes.DEFAULT
await safe_reply(update, context, f"❌ 验证失败:{result.get('msg') or result.get('reason') or '授权信息无效'}\n请重新发送:邮箱 Token")
async def cmd_me(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""查看当前 TG 用户绑定的授权信息。"""
user = update.effective_user
binding = await get_binding(user.id)
if not binding:
text = (
"👤 当前账号还没有绑定授权信息\n\n"
"绑定后我可以帮你识别授权状态和到期时间。\n"
"请发送 /bind,然后按提示到私聊里提交邮箱和 Token。"
)
else:
text = (
"👤 我的授权信息\n"
"━━━━━━━━━━━━━━━━━━━━\n"
f"📧 授权邮箱:{binding.get('email') or '-'}\n"
f"⏳ 到期时间:{binding.get('time_expire') or '未返回'}\n"
f"🔗 绑定时间:{binding.get('bound_at') or '-'}\n\n"
"如需更换授权,请先 /unbind,再 /bind 重新绑定。"
)
reply = await safe_reply(update, context, text)
if update.effective_chat.type != "private":
asyncio.create_task(auto_delete(update.message, seconds=60))
asyncio.create_task(auto_delete(reply, seconds=60))
async def cmd_unbind(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""解绑 harvest 账号"""
user = update.effective_user
@@ -131,5 +156,6 @@ async def auto_delete(message, seconds=60):
def register_bind(app):
app.add_handler(CommandHandler("start", cmd_start, filters.ChatType.PRIVATE))
app.add_handler(CommandHandler("bind", cmd_bind))
app.add_handler(CommandHandler("me", cmd_me))
app.add_handler(CommandHandler("unbind", cmd_unbind))
app.add_handler(MessageHandler(filters.TEXT & filters.ChatType.PRIVATE & ~filters.COMMAND, handle_private_bind_text), group=0)