From d52e9620229db858a5a1ec0433ba54d4538158b8 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Sun, 16 Nov 2025 20:07:52 +0300 Subject: [PATCH] fix /start and lastYear_or_1000games --- LichessClientTG_bot/bot.py | 1 + LichessClientTG_bot/config.py | 4 ++-- LichessClientTG_bot/formatters.py | 21 +++++++++++++++------ LichessClientTG_bot/i18n.py | 1 + about.md | 1 + 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/LichessClientTG_bot/bot.py b/LichessClientTG_bot/bot.py index 248407a..57c664b 100644 --- a/LichessClientTG_bot/bot.py +++ b/LichessClientTG_bot/bot.py @@ -974,6 +974,7 @@ class LichessBot: ) # Add handlers + application.add_handler(CommandHandler("start", self.start)) application.add_handler(CommandHandler("addgamer", self.addgamer_start)) application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, self.handle_username)) application.add_handler(addtoken_conv) diff --git a/LichessClientTG_bot/config.py b/LichessClientTG_bot/config.py index 5f6af4c..38d606a 100644 --- a/LichessClientTG_bot/config.py +++ b/LichessClientTG_bot/config.py @@ -4,10 +4,10 @@ from dotenv import load_dotenv load_dotenv() # Telegram Bot Configuration -TELEGRAM_BOT_TOKEN = "8241474807:AAH684LTY93aXRou4-LtqU5-p8LuEjzYn8U" +TELEGRAM_BOT_TOKEN = "7903295042:AAGBO2k8pfBDy4RoLRFsknwE7z0N-thAPI8" # Admin Panel Bot Configuration -ADMINPANEL_TELEGRAM_BOT_TOKEN = "7918349610:AAEZH7lbzdams31rCDZXeaAzFluDWfUQoLg" +ADMINPANEL_TELEGRAM_BOT_TOKEN = "8588876086:AAHoZncfhTCbul1BblpvnZMzvz7jAYVFmcw" # Lichess API Configuration LICHESS_API_BASE_URL = "https://lichess.org/api" diff --git a/LichessClientTG_bot/formatters.py b/LichessClientTG_bot/formatters.py index fc4a3f6..1874f16 100644 --- a/LichessClientTG_bot/formatters.py +++ b/LichessClientTG_bot/formatters.py @@ -188,7 +188,7 @@ class StatsFormatter: earliest_ts = data.get('earliest_game_ts') if isinstance(earliest_ts, int): earliest = datetime.fromtimestamp(earliest_ts).strftime("%d.%m.%Y") - header += f"\nStart of these 1000 games: {earliest}" + header += f"\n\n\nStart of these 1000 games: {earliest}" else: header = f"📈 {username}: last year (rated), games: {games_count}" # Use earliest actual game date instead of naive 'year ago' @@ -196,7 +196,7 @@ class StatsFormatter: if isinstance(earliest_ts, int) and isinstance(period_end, int): start_str = datetime.fromtimestamp(earliest_ts).strftime("%d.%m.%Y") end_str = datetime.fromtimestamp(period_end).strftime("%d.%m.%Y") - header += f"\nPeriod: {start_str}–{end_str}" + header += f"\n\n\nPeriod: {start_str}–{end_str}" # Body per mode lines = [] for mode in ["bullet", "blitz", "rapid", "classical", "correspondence"]: @@ -217,7 +217,16 @@ class StatsFormatter: lines.append( f"{emoji} {mode.title()}: {games_played} Δ {rating_change_str} R {rating_str} ✅ {wins} ❌ {losses} 🤝 {draws}" ) - # Total - # Do not print 'Итого' line per new requirement - body = "\n".join(lines) - return f"{header}\n{body}".rstrip() + # Join lines with newlines between each mode + # Between regular modes: one empty line (\n\n) + # Before last mode: two empty lines (\n\n\n) + if len(lines) == 0: + body = "" + elif len(lines) == 1: + body = lines[0] + else: + # All modes except last joined with one empty line + body = "\n\n".join(lines[:-1]) + # Add two empty lines before last mode + body += "\n\n\n" + lines[-1] + return f"{header}\n\n{body}" diff --git a/LichessClientTG_bot/i18n.py b/LichessClientTG_bot/i18n.py index db279ee..528d4fb 100644 --- a/LichessClientTG_bot/i18n.py +++ b/LichessClientTG_bot/i18n.py @@ -34,6 +34,7 @@ TRANSLATIONS = { "/today - Statistics for today\n" "/yesterday - Statistics for yesterday\n" "/week - Statistics for the week\n" + "/lastYear_or_1000games - Statistics for the last year or last 1000 rated games (whichever comes first)\n" "/setperiod - Set up periodic notifications for the active player\n" "(active player changes in the /getgamers menu)" ), diff --git a/about.md b/about.md index 0c0fee3..7ed1a5d 100644 --- a/about.md +++ b/about.md @@ -105,3 +105,4 @@ **Попробуйте бота прямо сейчас:** [https://t.me/LichessStat_bot](https://t.me/LichessStat_bot) +