fix(admin_bot): align /stat output and expand top list to 10
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 2m6s

Per-line strip() only stripped the first line's leading spaces, leaving
subsequent lines indented differently. RTL names (Arabic etc.) also
flipped the number/counter to the right via Telegram's bidi handling.
This commit is contained in:
vrubelroman 2026-07-03 13:48:28 +00:00
parent d9ff2aec57
commit 87ef82ef7f

View file

@ -212,11 +212,10 @@ async def stat_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
total_downloads = get_total_downloads() total_downloads = get_total_downloads()
total_users = get_total_users() total_users = get_total_users()
users_sent_link = get_users_sent_link_count() users_sent_link = get_users_sent_link_count()
top_users = get_top_active_users(5) top_users = get_top_active_users(10)
error_stats = get_error_stats() error_stats = get_error_stats()
# Форматируем статистику ошибок # Форматируем статистику ошибок
error_stats_text = ""
service_names = { service_names = {
'youtube': 'YouTube', 'youtube': 'YouTube',
'instagram': 'Instagram', 'instagram': 'Instagram',
@ -226,32 +225,32 @@ async def stat_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
'unknown': 'Unknown' 'unknown': 'Unknown'
} }
for service, count in sorted(error_stats.items()): error_lines = [
if count > 0: f"{service_names.get(service, service)}: {count}"
service_name = service_names.get(service, service) for service, count in sorted(error_stats.items())
error_stats_text += f"{service_name}: {count}\n" if count > 0
]
error_stats_text = "\n".join(error_lines) if error_lines else "Нет ошибок"
if not error_stats_text: # Форматируем топ активных пользователей.
error_stats_text = " Нет ошибок" # (LRM) перед каждой строкой не даёт Telegram переразвернуть строку
# справа налево из-за RTL-символов в имени (арабский и т.п.) — иначе номер
# Форматируем топ активных пользователей # и счётчик "уезжают" вправо и ломают выравнивание списка.
top_users_text = "" top_lines = [
for i, (uid, username, first_name, link_count) in enumerate(top_users, start=1): f"{i}. {('@' + username) if username else (first_name or str(uid))}{link_count}"
display_name = f"@{username}" if username else (first_name or str(uid)) for i, (uid, username, first_name, link_count) in enumerate(top_users, start=1)
top_users_text += f" {i}. {display_name}{link_count}\n" ]
top_users_text = "\n".join(top_lines) if top_lines else "Пока никто не отправлял ссылки"
if not top_users_text:
top_users_text = " Пока никто не отправлял ссылки"
stat_message = ( stat_message = (
f"📊 Статистика бота:\n\n" f"📊 Статистика бота:\n\n"
f"👥 Всего пользователей: {total_users}\n" f"👥 Всего пользователей: {total_users}\n"
f"🔗 Отправляли ссылки: {users_sent_link}\n" f"🔗 Отправляли ссылки: {users_sent_link}\n"
f"📹 Всего скачано видео: {total_downloads}\n\n" f"📹 Всего скачано видео: {total_downloads}\n\n"
f"🏆 Топ-5 активных пользователей:\n{top_users_text.strip()}\n\n" f"🏆 Топ-10 активных пользователей:\n{top_users_text}\n\n"
f"❌ Ошибки по сервисам:\n{error_stats_text.strip()}" f"❌ Ошибки по сервисам:\n{error_stats_text}"
) )
await update.message.reply_text(stat_message) await update.message.reply_text(stat_message)