58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""
|
||
Админский Telegram-бот chessCalc.
|
||
Показывает статистику использования клиентского бота.
|
||
"""
|
||
import os
|
||
import sys
|
||
from telegram import Update
|
||
from telegram.ext import Application, CommandHandler, ContextTypes
|
||
from telegram.constants import ParseMode
|
||
|
||
from bots.stats import get_stats, record_user
|
||
|
||
TOKEN = os.environ.get('ADMIN_BOT_TOKEN', '')
|
||
|
||
START_MSG = (
|
||
'*🔧 chessCalc — админский бот*\n\n'
|
||
'Доступные команды:\n'
|
||
'/stat — статистика использования клиентского бота\n'
|
||
'/start — эта справка'
|
||
)
|
||
|
||
|
||
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||
user = update.effective_user
|
||
record_user(user.id, user.username or '', user.first_name or '',
|
||
user.last_name or '')
|
||
await update.message.reply_text(START_MSG, parse_mode=ParseMode.MARKDOWN_V2)
|
||
|
||
|
||
async def stat(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||
user = update.effective_user
|
||
record_user(user.id, user.username or '', user.first_name or '',
|
||
user.last_name or '')
|
||
stats = get_stats()
|
||
text = (
|
||
'*📊 Статистика chessCalc*\n\n'
|
||
f'👤 Уникальных пользователей: *{stats["unique_users"]}*\n'
|
||
f'🔢 Всего запросов: *{stats["total_requests"]}*\n'
|
||
f'📅 За сегодня: *{stats["today_requests"]}*'
|
||
)
|
||
await update.message.reply_text(text, parse_mode=ParseMode.MARKDOWN_V2)
|
||
|
||
|
||
def main():
|
||
if not TOKEN:
|
||
print('ADMIN_BOT_TOKEN not set', file=sys.stderr)
|
||
sys.exit(1)
|
||
|
||
app = Application.builder().token(TOKEN).build()
|
||
app.add_handler(CommandHandler('start', start))
|
||
app.add_handler(CommandHandler('stat', stat))
|
||
|
||
print('Admin bot started', file=sys.stderr)
|
||
app.run_polling()
|
||
|
||
|
||
if __name__ == '__main__':
|
||
main()
|