Skip to content

Commit 20bec35

Browse files
authored
feat: add user display name to authorized users list command (#46)
* feat: add user display name to authorized users list command
1 parent 658e097 commit 20bec35

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

Thunder/bot/plugins/admin.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,21 @@ async def list_authorized_command(client: Client, message: Message):
234234

235235
text = MSG_ADMIN_AUTH_LIST_HEADER
236236
for i, user in enumerate(users, 1):
237+
display_name = "Unknown"
238+
try:
239+
try:
240+
tg_user = await client.get_users(user['user_id'])
241+
except FloodWait as e:
242+
await asyncio.sleep(e.value)
243+
tg_user = await client.get_users(user['user_id'])
244+
display_name = f"@{tg_user.username}" if tg_user.username else tg_user.first_name or "Unknown"
245+
except Exception:
246+
logger.error("Failed to fetch tg_user for user_id=%s", user['user_id'], exc_info=True)
247+
237248
text += MSG_AUTH_USER_INFO.format(
238-
i=i, user_id=user['user_id'],
249+
i=i,
250+
display_name=display_name,
251+
user_id=user['user_id'],
239252
authorized_by=user['authorized_by'],
240253
auth_time=user['authorized_at']
241254
)
@@ -502,4 +515,4 @@ async def _send_result(message: Message, status_msg: Message, result_text: str,
502515

503516

504517
def _fmt(value, decimals: int = 2) -> str:
505-
return f"{float(value):.{decimals}f}"
518+
return f"{float(value):.{decimals}f}"

Thunder/utils/messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
MSG_TOKEN_ACTIVATED = "✅ Token successfully activated!\n\n⏳ This token is valid for {duration_hours} hours."
8989
MSG_TOKEN_INVALID = "🚫 **Expired or Invalid Token.** Please click the button below to activate your access token."
9090
MSG_NO_AUTH_USERS = "ℹ️ **No Authorized Users Found:** The list is currently empty."
91-
MSG_AUTH_USER_INFO = """{i}. 👤 User ID: `{user_id}`
91+
MSG_AUTH_USER_INFO = """{i}. 👤: {display_name}
92+
• User ID: `{user_id}`
9293
• Authorized by: `{authorized_by}`
9394
• Date: `{auth_time}`\n\n"""
9495
MSG_ADMIN_AUTH_LIST_HEADER = "🔐 **Authorized Users List**\n\n"

0 commit comments

Comments
 (0)