fix: /edit command improvements

1. Accept any URL-like string as link (not just http/https)
   - Now detects URLs by pattern: contains "." and "/" (e.g., github.com/foo)

2. Show old -> new changes in update response
   - Now shows exactly what changed for verification
   - Helps user catch mistakes immediately
This commit is contained in:
shokollm
2026-04-04 23:29:03 +00:00
parent dfafefe071
commit 7a4d938c41

View File

@@ -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,6 +394,37 @@ async def cmd_update(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
return
if success:
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.")