From 3743dc6a45344a035d0c3d5826fa3412fc435751 Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Thu, 9 Apr 2026 14:08:57 +0000 Subject: [PATCH] fix: add sort and limit to /my command for consistency with /bounty - Add same sort_key logic as /bounty (due date first, then created_at) - Add default limit of 5 with "Showing X of Y" message - Add "all" flag to show expired bounties - Add delete button for consistency with /bounty Fixes #94 --- apps/telegram-bot/commands.py | 56 +++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/apps/telegram-bot/commands.py b/apps/telegram-bot/commands.py index f893334..71a1960 100644 --- a/apps/telegram-bot/commands.py +++ b/apps/telegram-bot/commands.py @@ -386,6 +386,17 @@ async def cmd_bounty(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: async def cmd_my(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: user_id = get_user_id(update) + args = extract_args(update.message.text) + + # Parse show_all flag + show_all = "all" in args + args = [a for a in args if a != "all"] + + # Parse optional limit + try: + limit = int(args[0]) if args else 5 + except (ValueError, IndexError): + limit = 5 if is_group(update): group_id = get_group_id(update) @@ -397,7 +408,25 @@ async def cmd_my(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: timezone_str = BOUNTY_SERVICE.get_timezone(room_id) - if not bounties: + now = int(time.time()) + cutoff_24h = now - 86400 + + def is_expired(b) -> bool: + return b.due_date_ts is not None and b.due_date_ts < cutoff_24h + + def sort_key(b): + if b.due_date_ts is not None: + return (0, b.due_date_ts) + return (1, b.created_at) + + # Filter expired and sort + filtered_bounties = [b for b in bounties if not is_expired(b) or show_all] + filtered_bounties.sort(key=sort_key) + + total_count = len(filtered_bounties) + displayed_bounties = filtered_bounties[:limit] + + if not displayed_bounties: msg = ( "You are not tracking any bounties." if is_group(update) @@ -406,10 +435,27 @@ async def cmd_my(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: await update.message.reply_text(msg) return - lines = [ - format_bounty(b, show_id=True, timezone_str=timezone_str) for b in bounties - ] - await update.message.reply_text("\n".join(lines), disable_web_page_preview=True) + lines = [] + if limit < total_count: + lines.append(f"Showing {limit} of {total_count} bounties:") + slice_length = 40 + elif show_all and total_count > limit: + lines.append(f"Showing {limit} of {total_count} bounties (including expired):") + slice_length = 40 + else: + lines.append(f"Showing {total_count} bounties:") + slice_length = 0 + + for b in displayed_bounties: + lines.append( + format_bounty(b, show_id=True, slice_length=slice_length, timezone_str=timezone_str) + ) + + keyboard = [[InlineKeyboardButton("🗑️ Delete", callback_data=f"del_msg:{user_id}")]] + reply_markup = InlineKeyboardMarkup(keyboard) + await update.message.reply_text( + "\n".join(lines), disable_web_page_preview=True, reply_markup=reply_markup + ) async def cmd_add(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: