feat(admin_bot): show link-senders count and top-5 active users in /stat
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 1m43s

Adds users.link_count, incremented in bot.py whenever a user submits
a recognized link (regardless of eventual download success), and
surfaces it in admin_bot's /stat as a count of users who ever sent a
link plus a top-5 leaderboard by link count.
This commit is contained in:
vrubelroman 2026-06-30 22:28:53 +00:00
parent 772e9fd5b4
commit d9ff2aec57
2 changed files with 67 additions and 5 deletions

19
bot.py
View file

@ -224,6 +224,9 @@ def init_database():
if 'locale' not in columns:
cursor.execute("ALTER TABLE users ADD COLUMN locale TEXT DEFAULT 'en'")
logger.info("Добавлена колонка locale в таблицу users")
if 'link_count' not in columns:
cursor.execute("ALTER TABLE users ADD COLUMN link_count INTEGER DEFAULT 0")
logger.info("Добавлена колонка link_count в таблицу users")
# Таблица статистики
cursor.execute('''
@ -377,6 +380,18 @@ def add_user(chat_id: int, username: str = None, first_name: str = None, locale:
logger.error(f"Ошибка при добавлении пользователя: {e}")
def increment_user_link_count(chat_id: int):
"""Увеличивает счётчик отправленных пользователем ссылок"""
try:
conn = sqlite3.connect(str(DB_FILE))
cursor = conn.cursor()
cursor.execute('UPDATE users SET link_count = link_count + 1 WHERE chat_id = ?', (chat_id,))
conn.commit()
conn.close()
except Exception as e:
logger.error(f"Ошибка при увеличении счётчика ссылок: {e}")
# ============================================================================
# УТИЛИТЫ
# ============================================================================
@ -1249,7 +1264,9 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
if chat_type == 'private':
await update.message.reply_text(get_text(locale, 'error_vk_not_video'))
return
increment_user_link_count(chat_id)
# Отправляем сообщение о начале обработки
status_message = await update.message.reply_text(get_text(locale, 'processing'))