fix: delay deletion of user interaction messages
This commit is contained in:
+6
-3
@@ -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):
|
||||
|
||||
+10
-5
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user