feat: store username when creating bounty for display

When adding a bounty, capture effective_user's username or first_name
and store it for display in /show. Now shows actual name instead of
just "User".
This commit is contained in:
shokollm
2026-04-05 01:36:30 +00:00
parent db1369c004
commit a1946e4c4e

View File

@@ -359,6 +359,9 @@ async def cmd_add(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
room_id = get_room_id(update) room_id = get_room_id(update)
timezone_str = BOUNTY_SERVICE.get_timezone(room_id) timezone_str = BOUNTY_SERVICE.get_timezone(room_id)
effective_user = update.effective_user
username = effective_user.username or effective_user.first_name or None
text, link, due_date_ts, _, _ = parse_args(args, timezone_str) text, link, due_date_ts, _, _ = parse_args(args, timezone_str)
if not text and not link: if not text and not link:
await update.message.reply_text("A bounty needs at least text or a link.") await update.message.reply_text("A bounty needs at least text or a link.")
@@ -371,6 +374,7 @@ async def cmd_add(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
text=text, text=text,
link=link, link=link,
due_date_ts=due_date_ts, due_date_ts=due_date_ts,
created_by_username=username,
) )
except PermissionError as e: except PermissionError as e:
await update.message.reply_text(f"{e}") await update.message.reply_text(f"{e}")
@@ -662,7 +666,10 @@ async def cmd_show(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
due_str = dt_due.strftime("%d %B %Y %H:%M") due_str = dt_due.strftime("%d %B %Y %H:%M")
lines.append(f"📅 {due_str} ({timezone_str})") lines.append(f"📅 {due_str} ({timezone_str})")
lines.append(f'👤 <a href="tg://user?id={bounty.created_by_user_id}">User</a>') display_name = bounty.created_by_username or f"User {bounty.created_by_user_id}"
lines.append(
f'👤 <a href="tg://user?id={bounty.created_by_user_id}">{display_name}</a>'
)
dt_created = datetime.fromtimestamp(bounty.created_at, tz=tz) dt_created = datetime.fromtimestamp(bounty.created_at, tz=tz)
created_str = dt_created.strftime("%Y-%m-%d %H:%M") created_str = dt_created.strftime("%Y-%m-%d %H:%M")