diff --git a/LichessClientTG_bot/bot.py b/LichessClientTG_bot/bot.py index c3fd447..313c3c7 100644 --- a/LichessClientTG_bot/bot.py +++ b/LichessClientTG_bot/bot.py @@ -1625,7 +1625,20 @@ class LichessBot: # Начало периода - текущее время минус period_minutes since_time = period_end_approx - timedelta(minutes=period_minutes) logger.info(f"📌 First check: period from {since_time} to {period_end_approx}") - + + # A collapsed backlog spanning way more than a normal check window isn't + # "recent activity" anymore — dumping a multi-week, game-by-game report + # on the user reads as spam, not a periodic update. Catch the checkpoint + # up silently in that case instead of sending the full notification. + STALE_BACKLOG_THRESHOLD = timedelta(hours=2) + is_stale_backlog = (period_end_approx - since_time) > STALE_BACKLOG_THRESHOLD + if is_stale_backlog: + logger.warning( + f"⏭️ {username}: collapsed window ({since_time} to {period_end_approx}) " + f"exceeds {STALE_BACKLOG_THRESHOLD}; catching up checkpoint silently, " + f"no notification will be sent for this stale backlog" + ) + since_timestamp = int(since_time.timestamp() * 1000) # Используем приблизительное время как until_timestamp # После получения ответа пересчитаем фактическое время @@ -1737,12 +1750,13 @@ class LichessBot: logger.info(f"🔍 Activity check result for {username}: has_games={has_games} (total={total_games}), has_puzzles={has_puzzles} (total={total_puzzles})") - # Отправляем уведомление только если есть реальная активность. + # Отправляем уведомление только если есть реальная активность и это не + # молчаливый догон устаревшего бэклога (is_stale_backlog, см. выше). # Ошибки форматирования/отправки НЕ перехватываются здесь: они должны # всплыть во внешний обработчик, чтобы чекпоинт не продвинулся и уже # обнаруженная активность была отправлена повторно на следующей попытке, # а не потеряна молча. - if has_games or has_puzzles: + if (has_games or has_puzzles) and not is_stale_backlog: logger.info(f"📊 Activity detected for {gamer['username']}, preparing notification...") user_lang = self.db.get_user_language(user_id) # Label the notification with the actual queried window, not the @@ -1765,6 +1779,8 @@ class LichessBot: logger.info(f"✅ Sent periodic notification for {gamer['username']} to user {user_id}") # Increment periodic notification counter self.counters.increment('periodic_notification') + elif is_stale_backlog and (has_games or has_puzzles): + logger.info(f"⏭️ Suppressed stale backlog notification for {gamer['username']} (had activity, but window too old)") else: logger.debug(f"⏭️ No activity found for {gamer['username']} in the last {period_minutes} minutes")