feat: add multi-ID delete support with per-ID results

- Add delete_bounties method to BountyService that returns individual
  results per bounty ID (deleted, not_found, permission_denied)
- Update cmd_delete to accept multiple IDs and show per-ID messages
- Add tests for delete_bounties

Example output:
/delete 1 2 3
 Bounty #1 deleted.
 Bounty #2 deleted.
 Bounty #3 not found.

Fixes #47
This commit is contained in:
shokollm
2026-04-04 06:39:11 +00:00
parent 42ed551554
commit 8069ed6465
3 changed files with 90 additions and 16 deletions

View File

@@ -210,32 +210,34 @@ cmd_edit = cmd_update
async def cmd_delete(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
args = extract_args(update.message.text)
if not args:
await update.message.reply_text("Usage: /delete <bounty_id>")
await update.message.reply_text("Usage: /delete <bounty_id> [bounty_id ...]")
return
try:
bounty_id = int(args[0])
bounty_ids = [int(arg) for arg in args]
except ValueError:
await update.message.reply_text("Invalid bounty ID.")
await update.message.reply_text("Invalid bounty ID(s).")
return
user_id = get_user_id(update)
room_id = get_room_id(update)
try:
success = BOUNTY_SERVICE.delete_bounty(
room_id=room_id,
bounty_id=bounty_id,
user_id=user_id,
)
except PermissionError as e:
await update.message.reply_text(f"{e}")
return
results = BOUNTY_SERVICE.delete_bounties(
room_id=room_id,
bounty_ids=bounty_ids,
user_id=user_id,
)
if success:
await update.message.reply_text(f"✅ Bounty #{bounty_id} deleted.")
else:
await update.message.reply_text("Bounty not found.")
lines = []
for bounty_id, result in results.items():
if result == "deleted":
lines.append(f"Bounty #{bounty_id} deleted.")
elif result == "not_found":
lines.append(f"⛔ Bounty #{bounty_id} not found.")
elif result == "permission_denied":
lines.append(f"⛔ Bounty #{bounty_id} - only admins can delete.")
await update.message.reply_text("\n".join(lines))
async def cmd_track(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: