add statistics
This commit is contained in:
parent
23de80f94d
commit
ceb62b408a
6 changed files with 318 additions and 3 deletions
|
|
@ -11,6 +11,7 @@ from telegram.ext import Application, CommandHandler, ContextTypes
|
|||
|
||||
from config import ADMINPANEL_TELEGRAM_BOT_TOKEN, DATABASE_PATH
|
||||
from database import Database
|
||||
from message_counters import MessageCounters
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
|
|
@ -24,6 +25,7 @@ class AdminBot:
|
|||
def __init__(self):
|
||||
self.db = Database()
|
||||
self.application = None
|
||||
self.counters = MessageCounters()
|
||||
|
||||
async def send_notification(self, message: str):
|
||||
"""Send notification to admin chat"""
|
||||
|
|
@ -115,10 +117,30 @@ class AdminBot:
|
|||
|
||||
conn.close()
|
||||
|
||||
# Get message counters statistics
|
||||
stats = self.counters.get_stats_summary()
|
||||
|
||||
# Filter out commands that should not be displayed
|
||||
excluded_commands = {'lang', 'resetlang', 'start'}
|
||||
filtered_stats = {
|
||||
cmd: data for cmd, data in stats['by_command'].items()
|
||||
if cmd not in excluded_commands
|
||||
}
|
||||
|
||||
# Format message counters
|
||||
counters_text = "\n".join([
|
||||
f" • {cmd}: {data['total']} (сегодня: {data['today']})"
|
||||
for cmd, data in sorted(filtered_stats.items())
|
||||
])
|
||||
|
||||
message = (
|
||||
f"📊 <b>Статистика базы данных</b>\n\n"
|
||||
f"👥 Пользователей Telegram: {users_count}\n"
|
||||
f"🎮 Отслеживаемых игроков: {gamers_count}"
|
||||
f"🎮 Отслеживаемых игроков: {gamers_count}\n\n"
|
||||
f"📨 <b>Счетчики сообщений</b>\n\n"
|
||||
f"Всего отправлено: <b>{stats['total_all_time']}</b>\n"
|
||||
f"Сегодня отправлено: <b>{stats['total_today']}</b>\n\n"
|
||||
f"<b>По командам:</b>\n{counters_text}"
|
||||
)
|
||||
await update.message.reply_text(message, parse_mode='HTML')
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue