fix bug push from timer

This commit is contained in:
vrubelroman 2025-11-20 01:22:52 +03:00
parent 278c5b9c40
commit ef9aa3d3df
3 changed files with 402 additions and 18 deletions

View file

@ -1243,16 +1243,31 @@ class LichessBot:
# Проверяем наличие реальной активности
has_games = False
total_games = 0
if games_data and games_data.get('data'):
total_games = games_data.get('data', {}).get('total', {}).get('games_played', 0)
has_games = total_games > 0
if games_data:
# Логируем структуру ответа для отладки
logger.debug(f"Games data structure for {gamer['username']}: {games_data}")
if games_data.get('data'):
total_games = games_data.get('data', {}).get('total', {}).get('games_played', 0)
has_games = total_games > 0
# Также проверяем games_count на верхнем уровне
elif games_data.get('games_count', 0) > 0:
total_games = games_data.get('games_count', 0)
has_games = True
else:
logger.warning(f"No games_data returned for {gamer['username']}")
has_puzzles = False
if puzzles_data and puzzles_data.get('data'):
total_puzzles = puzzles_data.get('data', {}).get('total_attempts', 0)
has_puzzles = total_puzzles > 0
total_puzzles = 0
if puzzles_data:
if puzzles_data.get('data'):
total_puzzles = puzzles_data.get('data', {}).get('total_attempts', 0)
has_puzzles = total_puzzles > 0
# Также проверяем puzzles_in_period на верхнем уровне
elif puzzles_data.get('puzzles_in_period', 0) > 0:
total_puzzles = puzzles_data.get('puzzles_in_period', 0)
has_puzzles = True
logger.info(f"Activity check for {gamer['username']}: has_games={has_games}, has_puzzles={has_puzzles}")
logger.info(f"Activity check for {gamer['username']}: has_games={has_games} (total={total_games}), has_puzzles={has_puzzles} (total={total_puzzles})")
# Отправляем уведомление только если есть реальная активность
if has_games or has_puzzles:
@ -1271,29 +1286,23 @@ class LichessBot:
text=notification
)
logger.info(f"✅ Sent periodic notification for {gamer['username']} to user {user_id}")
# Обновляем время начала на текущее время после успешной отправки уведомления
self.period_start_times[task_key] = now
# Increment periodic notification counter
self.counters.increment('periodic_notification')
except Exception as e:
logger.error(f"❌ Failed to send notification to user {user_id}: {e}")
import traceback
logger.error(f"Traceback: {traceback.format_exc()}")
# Обновляем время начала даже при ошибке отправки, чтобы не зацикливаться
self.period_start_times[task_key] = now
else:
logger.error(f"❌ Application not initialized, cannot send notification for {gamer['username']} to user {user_id}")
self.period_start_times[task_key] = now
except Exception as e:
logger.error(f"Error formatting notification for {gamer['username']}: {e}")
import traceback
logger.error(f"Traceback: {traceback.format_exc()}")
# Обновляем время начала даже при ошибке форматирования
self.period_start_times[task_key] = now
else:
logger.debug(f"⏭️ No activity found for {gamer['username']} in the last {period_minutes} minutes")
# Обновляем время начала на текущее время даже если нет активности
self.period_start_times[task_key] = now
else:
logger.debug(f"⏭️ No activity found for {gamer['username']} in the last {period_minutes} minutes")
# Всегда обновляем время начала на текущее время после проверки (независимо от наличия активности)
self.period_start_times[task_key] = now
except asyncio.CancelledError:
logger.info(f"Periodic check cancelled for {gamer['username']}")