fix: single delete button per message, use query.message.delete()

- /bounty now shows only ONE delete button (not per-bounty)
- Callback uses query.message.delete() instead of delete_message by ID
- This is more reliable and simpler
This commit is contained in:
shokollm
2026-04-04 23:45:19 +00:00
parent 7b64da7897
commit cfe5f019f2

View File

@@ -155,12 +155,11 @@ async def cmd_delete_message(update: Update, ctx: ContextTypes.DEFAULT_TYPE) ->
return return
parts = data.split(":") parts = data.split(":")
if len(parts) != 3: if len(parts) != 2:
return return
try: try:
message_id = int(parts[1]) expected_user_id = int(parts[1])
expected_user_id = int(parts[2])
except ValueError: except ValueError:
return return
@@ -170,12 +169,10 @@ async def cmd_delete_message(update: Update, ctx: ContextTypes.DEFAULT_TYPE) ->
return return
try: try:
await ctx.bot.delete_message( await query.message.delete()
chat_id=query.message.chat_id, message_id=message_id
)
await query.answer("Deleted") await query.answer("Deleted")
except Exception: except Exception as e:
await query.answer("Could not delete message", show_alert=True) await query.answer(f"Could not delete: {e}", show_alert=True)
def is_group(update: Update) -> bool: def is_group(update: Update) -> bool:
@@ -253,19 +250,11 @@ async def cmd_bounty(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
lines.append(f"Showing {total_count} bounties:") lines.append(f"Showing {total_count} bounties:")
slice_length = 0 slice_length = 0
keyboard = []
for b in displayed_bounties: for b in displayed_bounties:
lines.append(format_bounty(b, show_id=True, slice_length=slice_length)) lines.append(format_bounty(b, show_id=True, slice_length=slice_length))
keyboard.append(
[
InlineKeyboardButton(
"🗑️ Delete",
callback_data=f"del_msg:{update.message.message_id + len(lines)}:{user_id}",
)
]
)
reply_markup = InlineKeyboardMarkup(keyboard) if keyboard else None keyboard = [[InlineKeyboardButton("🗑️ Delete", callback_data=f"del_msg:{user_id}")]]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text( await update.message.reply_text(
"\n".join(lines), disable_web_page_preview=True, reply_markup=reply_markup "\n".join(lines), disable_web_page_preview=True, reply_markup=reply_markup
) )