bug today
This commit is contained in:
parent
faf6ec0c35
commit
4dc5539da2
5 changed files with 189 additions and 38 deletions
|
|
@ -732,8 +732,11 @@ class LichessBot:
|
|||
"""Get statistics for a period - shows stats for all players with activity"""
|
||||
user_id = update.effective_user.id
|
||||
|
||||
logger.info(f"🔍 get_stats called: user_id={user_id}, period={period}")
|
||||
|
||||
# Get all gamers for this user
|
||||
gamers = self.db.get_user_gamers(user_id)
|
||||
logger.info(f"🔍 Found {len(gamers)} gamers for user {user_id}: {[g['username'] for g in gamers]}")
|
||||
|
||||
lang = self.get_user_language_from_update(update)
|
||||
if not gamers:
|
||||
|
|
@ -752,6 +755,7 @@ class LichessBot:
|
|||
has_any_activity = False
|
||||
for i, gamer in enumerate(gamers):
|
||||
username = gamer['username']
|
||||
logger.info(f"🔍 Processing gamer {i+1}/{len(gamers)}: {username} for period {period}")
|
||||
|
||||
# Send message about processing this player
|
||||
processing_msg = None
|
||||
|
|
@ -761,15 +765,28 @@ class LichessBot:
|
|||
pass
|
||||
|
||||
# Get stats based on period
|
||||
if period == "today":
|
||||
data = await self.lichess_api.get_today_stats(username)
|
||||
elif period == "yesterday":
|
||||
data = await self.lichess_api.get_yesterday_stats(username)
|
||||
elif period == "week":
|
||||
data = await self.lichess_api.get_week_stats(username)
|
||||
else:
|
||||
await update.message.reply_text(t('unknown_period', lang))
|
||||
return
|
||||
try:
|
||||
logger.info(f"🔍 Making API request for {username}, period={period}")
|
||||
if period == "today":
|
||||
data = await self.lichess_api.get_today_stats(username)
|
||||
elif period == "yesterday":
|
||||
data = await self.lichess_api.get_yesterday_stats(username)
|
||||
elif period == "week":
|
||||
data = await self.lichess_api.get_week_stats(username)
|
||||
else:
|
||||
await update.message.reply_text(t('unknown_period', lang))
|
||||
return
|
||||
|
||||
logger.info(f"🔍 API response for {username}: data={data is not None}, type={type(data)}")
|
||||
if data:
|
||||
logger.info(f"🔍 API response keys: {data.keys() if isinstance(data, dict) else 'not a dict'}")
|
||||
if isinstance(data, dict) and 'message' in data:
|
||||
logger.info(f"🔍 API message: {data.get('message')}")
|
||||
except Exception as e:
|
||||
logger.error(f"❌ Error getting stats for {username}: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
data = None
|
||||
|
||||
# Delete processing message
|
||||
if processing_msg:
|
||||
|
|
@ -780,27 +797,40 @@ class LichessBot:
|
|||
|
||||
# Check if there's activity
|
||||
has_activity = False
|
||||
if data and data.get('data'):
|
||||
api_data = data.get('data', {})
|
||||
tasks = api_data.get('tasks', {})
|
||||
games = api_data.get('games', {})
|
||||
|
||||
# Check for puzzles activity
|
||||
if tasks and tasks.get('total', 0) > 0:
|
||||
has_activity = True
|
||||
|
||||
# Check for games activity
|
||||
if games:
|
||||
for game_type, game_data in games.items():
|
||||
if game_data and game_data.get('games_played', 0) > 0:
|
||||
has_activity = True
|
||||
break
|
||||
if data:
|
||||
if data.get('data'):
|
||||
api_data = data.get('data', {})
|
||||
tasks = api_data.get('tasks', {})
|
||||
games = api_data.get('games', {})
|
||||
|
||||
logger.info(f"🔍 Activity check for {username}: tasks={tasks}, games={games}")
|
||||
|
||||
# Check for puzzles activity
|
||||
if tasks and tasks.get('total', 0) > 0:
|
||||
has_activity = True
|
||||
logger.info(f"✅ {username} has puzzles activity: {tasks.get('total')}")
|
||||
|
||||
# Check for games activity
|
||||
if games:
|
||||
for game_type, game_data in games.items():
|
||||
if game_data and game_data.get('games_played', 0) > 0:
|
||||
has_activity = True
|
||||
logger.info(f"✅ {username} has {game_type} activity: {game_data.get('games_played')} games")
|
||||
break
|
||||
else:
|
||||
# API вернул ответ, но без данных (нет активности)
|
||||
message = data.get('message', 'No message')
|
||||
logger.info(f"ℹ️ API response for {username}: {message} (no activity data)")
|
||||
else:
|
||||
logger.warning(f"⚠️ No response data for {username}: data is None")
|
||||
|
||||
# Only send response if there's activity
|
||||
if has_activity:
|
||||
formatted_response = StatsFormatter.format_stats_response(data, username, period, lang)
|
||||
await update.message.reply_text(formatted_response)
|
||||
has_any_activity = True
|
||||
else:
|
||||
logger.info(f"ℹ️ No activity found for {username}, skipping response")
|
||||
|
||||
# Add delay between requests to avoid rate limiting
|
||||
if i < len(gamers) - 1:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue