messages when doing questions

This commit is contained in:
vrubelroman 2025-11-16 23:10:08 +03:00
parent 033a0db12f
commit c39bb33282
6 changed files with 132 additions and 25 deletions

View file

@ -662,11 +662,24 @@ class LichessBot:
)
return
# Send initial message about processing
try:
await update.message.reply_text(t('stats_processing', lang), parse_mode='HTML')
except Exception:
pass
# Process each gamer
has_any_activity = False
for i, gamer in enumerate(gamers):
username = gamer['username']
# Send message about processing this player
processing_msg = None
try:
processing_msg = await update.message.reply_text(t('stats_player_processing', lang, username=username), parse_mode='HTML')
except Exception:
pass
# Get stats based on period
if period == "today":
data = await self.lichess_api.get_today_stats(username)
@ -678,6 +691,13 @@ class LichessBot:
await update.message.reply_text(t('unknown_period', lang))
return
# Delete processing message
if processing_msg:
try:
await processing_msg.delete()
except Exception:
pass
# Check if there's activity
has_activity = False
if data and data.get('data'):
@ -704,11 +724,14 @@ class LichessBot:
# Add delay between requests to avoid rate limiting
if i < len(gamers) - 1:
await asyncio.sleep(3.0)
await asyncio.sleep(1.0)
# If no activity for any player
if not has_any_activity:
await update.message.reply_text(t('no_activity', lang))
else:
# Send final message that all is done
await update.message.reply_text(t('stats_all_done', lang))
# Increment counter for the period command
if period == "today":
@ -769,14 +792,22 @@ class LichessBot:
try:
# Send message about processing this player
processing_msg = None
try:
await update.message.reply_text(t('last_year_1000_player_processing', lang, username=username), parse_mode='HTML')
processing_msg = await update.message.reply_text(t('last_year_1000_player_processing', lang, username=username), parse_mode='HTML')
except Exception:
pass
# Get data for this player
data = await self.lichess_api.get_games_period(username, since_ms, now_ms, rated_only=True)
# Delete processing message
if processing_msg:
try:
await processing_msg.delete()
except Exception:
pass
if data:
# Check if there's activity (games_count > 0)
games_count = data.get('games_count', 0)
@ -797,6 +828,9 @@ class LichessBot:
# If no activity for any player
if not has_any_activity:
await update.message.reply_text(t('no_activity', lang))
else:
# Send final message that all is done
await update.message.reply_text(t('stats_all_done', lang))
self.counters.increment('last_year_1000')