add lastYear_or_1000games
This commit is contained in:
parent
7232a8d304
commit
3226d4c162
3 changed files with 92 additions and 1 deletions
|
|
@ -21,6 +21,7 @@ from formatters import StatsFormatter
|
|||
from i18n import t
|
||||
from admin_bot import get_admin_bot, init_admin_bot
|
||||
from message_counters import MessageCounters
|
||||
import time
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
|
|
@ -624,6 +625,32 @@ class LichessBot:
|
|||
"""Week command"""
|
||||
await self.get_stats(update, context, "week")
|
||||
|
||||
async def last_year_or_1000games(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""Get last year stats or last 1000 rated games, whichever limits first"""
|
||||
user_id = update.effective_user.id
|
||||
active_gamer = self.db.get_user_active_gamer(user_id)
|
||||
lang = self.get_user_language_from_update(update)
|
||||
if not active_gamer:
|
||||
await update.message.reply_text(
|
||||
t('no_active_gamer', lang)
|
||||
)
|
||||
return
|
||||
username = active_gamer['username']
|
||||
now_ms = int(time.time() * 1000)
|
||||
year_ms = 365 * 24 * 3600 * 1000
|
||||
since_ms = now_ms - year_ms
|
||||
try:
|
||||
data = await self.lichess_api.get_games_period(username, since_ms, now_ms, rated_only=True)
|
||||
if not data:
|
||||
await update.message.reply_text(t('no_data', lang))
|
||||
return
|
||||
text = StatsFormatter.format_last_year_or_1000(data, username, lang)
|
||||
await update.message.reply_text(text)
|
||||
self.counters.increment('last_year_1000')
|
||||
except Exception as e:
|
||||
logger.error(f"/lastYear_or_1000games error: {e}")
|
||||
await update.message.reply_text(f"Error: {e}")
|
||||
|
||||
async def setperiod(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""Set period command"""
|
||||
user_id = update.effective_user.id
|
||||
|
|
@ -906,6 +933,7 @@ class LichessBot:
|
|||
application.add_handler(CommandHandler("today", self.today))
|
||||
application.add_handler(CommandHandler("yesterday", self.yesterday))
|
||||
application.add_handler(CommandHandler("week", self.week))
|
||||
application.add_handler(CommandHandler("lastYear_or_1000games", self.last_year_or_1000games))
|
||||
application.add_handler(CommandHandler("setperiod", self.setperiod))
|
||||
application.add_handler(CommandHandler("lang", self.check_language))
|
||||
application.add_handler(CommandHandler("resetlang", self.reset_language))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue