bug today

This commit is contained in:
vrubelroman 2025-11-20 03:14:06 +03:00
parent faf6ec0c35
commit 4dc5539da2
5 changed files with 189 additions and 38 deletions

View file

@ -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:

View file

@ -37,19 +37,31 @@ class LichessAPI:
async def get_today_stats(self, username: str) -> Optional[Dict[str, Any]]:
"""Get today's statistics from our stats API"""
logger.info(f"🔍 LichessAPI.get_today_stats: username={username}, stats_base_url={self.stats_base_url}")
await self.rate_limiter.wait_if_needed()
url = f"{self.stats_base_url}/stats/{username}/today"
logger.info(f"🔍 Making request to: {url}")
try:
async with aiohttp.ClientSession() as session:
async with session.get(
f"{self.stats_base_url}/stats/{username}/today"
) as response:
async with session.get(url) as response:
logger.info(f"🔍 Response status: {response.status} for {username}")
if response.status == 200:
return await response.json()
result = await response.json()
logger.info(f"🔍 Successfully got stats for {username}: {result.get('message', 'no message')}")
return result
else:
logger.error(f"Failed to get today stats: {response.status}")
error_text = await response.text()
logger.error(f"❌ Failed to get today stats for {username}: status={response.status}, error={error_text[:200]}")
return None
except aiohttp.ClientError as e:
logger.error(f"❌ Client error getting today stats for {username}: {e}")
import traceback
logger.error(traceback.format_exc())
return None
except Exception as e:
logger.error(f"Error getting today stats: {e}")
logger.error(f"❌ Error getting today stats for {username}: {e}")
import traceback
logger.error(traceback.format_exc())
return None
async def get_yesterday_stats(self, username: str) -> Optional[Dict[str, Any]]: