fix /start and lastYear_or_1000games
This commit is contained in:
parent
9011b3015b
commit
d52e962022
5 changed files with 20 additions and 8 deletions
|
|
@ -974,6 +974,7 @@ class LichessBot:
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add handlers
|
# Add handlers
|
||||||
|
application.add_handler(CommandHandler("start", self.start))
|
||||||
application.add_handler(CommandHandler("addgamer", self.addgamer_start))
|
application.add_handler(CommandHandler("addgamer", self.addgamer_start))
|
||||||
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, self.handle_username))
|
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, self.handle_username))
|
||||||
application.add_handler(addtoken_conv)
|
application.add_handler(addtoken_conv)
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ from dotenv import load_dotenv
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
# Telegram Bot Configuration
|
# Telegram Bot Configuration
|
||||||
TELEGRAM_BOT_TOKEN = "8241474807:AAH684LTY93aXRou4-LtqU5-p8LuEjzYn8U"
|
TELEGRAM_BOT_TOKEN = "7903295042:AAGBO2k8pfBDy4RoLRFsknwE7z0N-thAPI8"
|
||||||
|
|
||||||
# Admin Panel Bot Configuration
|
# Admin Panel Bot Configuration
|
||||||
ADMINPANEL_TELEGRAM_BOT_TOKEN = "7918349610:AAEZH7lbzdams31rCDZXeaAzFluDWfUQoLg"
|
ADMINPANEL_TELEGRAM_BOT_TOKEN = "8588876086:AAHoZncfhTCbul1BblpvnZMzvz7jAYVFmcw"
|
||||||
|
|
||||||
# Lichess API Configuration
|
# Lichess API Configuration
|
||||||
LICHESS_API_BASE_URL = "https://lichess.org/api"
|
LICHESS_API_BASE_URL = "https://lichess.org/api"
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ class StatsFormatter:
|
||||||
earliest_ts = data.get('earliest_game_ts')
|
earliest_ts = data.get('earliest_game_ts')
|
||||||
if isinstance(earliest_ts, int):
|
if isinstance(earliest_ts, int):
|
||||||
earliest = datetime.fromtimestamp(earliest_ts).strftime("%d.%m.%Y")
|
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:
|
else:
|
||||||
header = f"📈 {username}: last year (rated), games: {games_count}"
|
header = f"📈 {username}: last year (rated), games: {games_count}"
|
||||||
# Use earliest actual game date instead of naive 'year ago'
|
# 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):
|
if isinstance(earliest_ts, int) and isinstance(period_end, int):
|
||||||
start_str = datetime.fromtimestamp(earliest_ts).strftime("%d.%m.%Y")
|
start_str = datetime.fromtimestamp(earliest_ts).strftime("%d.%m.%Y")
|
||||||
end_str = datetime.fromtimestamp(period_end).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
|
# Body per mode
|
||||||
lines = []
|
lines = []
|
||||||
for mode in ["bullet", "blitz", "rapid", "classical", "correspondence"]:
|
for mode in ["bullet", "blitz", "rapid", "classical", "correspondence"]:
|
||||||
|
|
@ -217,7 +217,16 @@ class StatsFormatter:
|
||||||
lines.append(
|
lines.append(
|
||||||
f"{emoji} {mode.title()}: {games_played} Δ {rating_change_str} R {rating_str} ✅ {wins} ❌ {losses} 🤝 {draws}"
|
f"{emoji} {mode.title()}: {games_played} Δ {rating_change_str} R {rating_str} ✅ {wins} ❌ {losses} 🤝 {draws}"
|
||||||
)
|
)
|
||||||
# Total
|
# Join lines with newlines between each mode
|
||||||
# Do not print 'Итого' line per new requirement
|
# Between regular modes: one empty line (\n\n)
|
||||||
body = "\n".join(lines)
|
# Before last mode: two empty lines (\n\n\n)
|
||||||
return f"{header}\n{body}".rstrip()
|
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}"
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ TRANSLATIONS = {
|
||||||
"/today - Statistics for today\n"
|
"/today - Statistics for today\n"
|
||||||
"/yesterday - Statistics for yesterday\n"
|
"/yesterday - Statistics for yesterday\n"
|
||||||
"/week - Statistics for the week\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"
|
"/setperiod - Set up periodic notifications for the active player\n"
|
||||||
"(active player changes in the /getgamers menu)"
|
"(active player changes in the /getgamers menu)"
|
||||||
),
|
),
|
||||||
|
|
|
||||||
1
about.md
1
about.md
|
|
@ -105,3 +105,4 @@
|
||||||
|
|
||||||
**Попробуйте бота прямо сейчас:** [https://t.me/LichessStat_bot](https://t.me/LichessStat_bot)
|
**Попробуйте бота прямо сейчас:** [https://t.me/LichessStat_bot](https://t.me/LichessStat_bot)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue