diff --git a/handlers/bind.py b/handlers/bind.py index ee85b32..44c9738 100644 --- a/handlers/bind.py +++ b/handlers/bind.py @@ -24,7 +24,8 @@ async def cmd_bind(update: Update, context: ContextTypes.DEFAULT_TYPE): f"📅 绑定时间: {existing['bound_at']}\n\n" f"如需重新绑定,先 /unbind" ) - asyncio.create_task(auto_delete(reply)) + asyncio.create_task(auto_delete(update.message, seconds=60)) + asyncio.create_task(auto_delete(reply, seconds=60)) return token, url = generate_bind_token(user.id, user.username or user.first_name) @@ -34,7 +35,8 @@ async def cmd_bind(update: Update, context: ContextTypes.DEFAULT_TYPE): f"请点击以下链接完成绑定:\n{url}\n\n" "⏳ 链接 5 分钟内有效" ) - asyncio.create_task(auto_delete(reply)) + 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): @@ -46,7 +48,8 @@ async def cmd_unbind(update: Update, context: ContextTypes.DEFAULT_TYPE): await Action.create(action="UNBIND", user_id=user.id, username=user.username) else: reply = await update.message.reply_text("❌ 你没有绑定的账号") - asyncio.create_task(auto_delete(reply)) + asyncio.create_task(auto_delete(update.message, seconds=60)) + asyncio.create_task(auto_delete(reply, seconds=60)) async def auto_delete(message, seconds=60): diff --git a/handlers/fun.py b/handlers/fun.py index 8106077..d90a679 100644 --- a/handlers/fun.py +++ b/handlers/fun.py @@ -55,7 +55,8 @@ async def cmd_checkin(update: Update, context: ContextTypes.DEFAULT_TYPE): ) else: reply = await update.message.reply_text("❌ 你今天已经签到过了") - asyncio.create_task(auto_delete(reply)) + asyncio.create_task(auto_delete(update.message, seconds=60)) + asyncio.create_task(auto_delete(reply, seconds=60)) async def cmd_trivia(update: Update, context: ContextTypes.DEFAULT_TYPE): @@ -68,7 +69,8 @@ async def cmd_trivia(update: Update, context: ContextTypes.DEFAULT_TYPE): context.user_data["trivia_answer"] = q["a"] context.user_data["trivia_options"] = q["opts"] reply = await update.message.reply_text(text) - asyncio.create_task(auto_delete(reply)) + asyncio.create_task(auto_delete(update.message, seconds=60)) + asyncio.create_task(auto_delete(reply, seconds=60)) async def cmd_score(update: Update, context: ContextTypes.DEFAULT_TYPE): @@ -83,7 +85,8 @@ async def cmd_score(update: Update, context: ContextTypes.DEFAULT_TYPE): for s in scores: text += f"🎮 {s.game_type}: {s.score} 分 (胜率 {s.wins}/{s.total})\n" reply = await update.message.reply_text(text) - asyncio.create_task(auto_delete(reply)) + asyncio.create_task(auto_delete(update.message, seconds=60)) + asyncio.create_task(auto_delete(reply, seconds=60)) async def cmd_rank(update: Update, context: ContextTypes.DEFAULT_TYPE): @@ -98,7 +101,8 @@ async def cmd_rank(update: Update, context: ContextTypes.DEFAULT_TYPE): medal = medals[i] if i < 3 else f" {i+1}." text += f"{medal} @{s.username or s.user_id} — {s.score} 分\n" reply = await update.message.reply_text(text) - asyncio.create_task(auto_delete(reply)) + asyncio.create_task(auto_delete(update.message, seconds=60)) + asyncio.create_task(auto_delete(reply, seconds=60)) async def handle_trivia_answer(update: Update, context: ContextTypes.DEFAULT_TYPE): @@ -138,7 +142,8 @@ async def handle_trivia_answer(update: Update, context: ContextTypes.DEFAULT_TYP f"📊 当前积分:{result['score']}" ) reply = await msg.reply_text(text) - asyncio.create_task(auto_delete(reply)) + asyncio.create_task(auto_delete(msg, seconds=60)) + asyncio.create_task(auto_delete(reply, seconds=60)) raise ApplicationHandlerStop diff --git a/handlers/knowledge.py b/handlers/knowledge.py index 3aa4add..9d4e056 100644 --- a/handlers/knowledge.py +++ b/handlers/knowledge.py @@ -117,11 +117,13 @@ async def cmd_ask(update: Update, context: ContextTypes.DEFAULT_TYPE): "例如: /ask 怎么安装收割机\n" f"文档地址: {config.SITE_URL}" ) - asyncio.create_task(auto_delete(reply)) + asyncio.create_task(auto_delete(update.message, seconds=60)) + asyncio.create_task(auto_delete(reply, seconds=60)) return logger.info(f"📩 用户提问: [{update.message.from_user.username}] {query}") searching_msg = await safe_send(update, context, "🔍 正在搜索知识库并整理详细答案...") + asyncio.create_task(auto_delete(update.message, seconds=60)) try: from services.knowledge_base import ask_knowledge_base diff --git a/handlers/night_mode.py b/handlers/night_mode.py index b6ea36a..d0f2e7d 100644 --- a/handlers/night_mode.py +++ b/handlers/night_mode.py @@ -25,7 +25,8 @@ async def cmd_night(update: Update, context: ContextTypes.DEFAULT_TYPE): "/night on 开启\n" "/night off 关闭" ) - asyncio.create_task(auto_delete(reply)) + asyncio.create_task(auto_delete(update.message, seconds=60)) + asyncio.create_task(auto_delete(reply, seconds=60)) return cmd = args[0].lower() @@ -38,7 +39,8 @@ async def cmd_night(update: Update, context: ContextTypes.DEFAULT_TYPE): else: reply = await update.message.reply_text("❓ 用法: /night on|off") - asyncio.create_task(auto_delete(reply)) + asyncio.create_task(auto_delete(update.message, seconds=60)) + asyncio.create_task(auto_delete(reply, seconds=60)) async def auto_delete(message, seconds=60): diff --git a/handlers/verify.py b/handlers/verify.py index f6e4c3d..4f7ae08 100644 --- a/handlers/verify.py +++ b/handlers/verify.py @@ -51,6 +51,7 @@ async def handle_verify_answer(update: Update, context: ContextTypes.DEFAULT_TYP user_id = context.user_data.get("verify_user_id", update.effective_user.id) answer = update.message.text.strip() result = await check_answer(user_id, answer) + asyncio.create_task(auto_delete(update.message, seconds=60)) if result["ok"]: context.user_data["verifying"] = False