diff --git a/apps/telegram-bot/commands.py b/apps/telegram-bot/commands.py index b51eefd..42b907b 100644 --- a/apps/telegram-bot/commands.py +++ b/apps/telegram-bot/commands.py @@ -66,14 +66,19 @@ def parse_args( clear_link = False clear_date = False + def is_url(s: str) -> bool: + if not s: + return False + if s.startswith("http://") or s.startswith("https://"): + return True + return "." in s and "/" in s + i = 0 while i < len(args): arg = args[i] if arg == "-link": - if i + 1 < len(args) and ( - args[i + 1].startswith("http://") or args[i + 1].startswith("https://") - ): + if i + 1 < len(args) and is_url(args[i + 1]): link = args[i + 1] i += 2 else: @@ -91,7 +96,7 @@ def parse_args( else: clear_date = True i += 1 - elif not link and (arg.startswith("http://") or arg.startswith("https://")): + elif not link and is_url(arg): link = arg i += 1 elif due_date_ts is None: @@ -365,6 +370,11 @@ async def cmd_update(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: user_id = get_user_id(update) room_id = get_room_id(update) + old_bounty = BOUNTY_SERVICE.get_bounty(room_id, bounty_id) + if not old_bounty: + await update.message.reply_text("Bounty not found.") + return + try: success = BOUNTY_SERVICE.update_bounty( room_id=room_id, @@ -384,7 +394,38 @@ async def cmd_update(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: return if success: - await update.message.reply_text(f"✅ Bounty #{bounty_id} updated.") + changes = [] + if text is not None: + old_text = old_bounty.text or "(none)" + changes.append(f"Text: {old_text} → {text}") + if link is not None: + old_link = old_bounty.link or "(none)" + changes.append(f"Link: {old_link} → {link}") + if due_date_ts is not None: + old_date = ( + time.strftime("%d %b %Y", time.localtime(old_bounty.due_date_ts)) + if old_bounty.due_date_ts + else "(none)" + ) + new_date = time.strftime("%d %b %Y", time.localtime(due_date_ts)) + changes.append(f"Date: {old_date} → {new_date}") + if clear_link: + old_link = old_bounty.link or "(none)" + changes.append(f"Link: {old_link} → (cleared)") + if clear_date: + old_date = ( + time.strftime("%d %b %Y", time.localtime(old_bounty.due_date_ts)) + if old_bounty.due_date_ts + else "(none)" + ) + changes.append(f"Date: {old_date} → (cleared)") + + if changes: + await update.message.reply_text( + f"✅ Bounty #{bounty_id} updated:\n" + "\n".join(changes) + ) + else: + await update.message.reply_text(f"✅ Bounty #{bounty_id} updated.") else: await update.message.reply_text("Bounty not found.")