fix: persist last_offense_time and reset offenses after 24h

last_offense_time was in-memory only — lost on restart, so the
offense_reset_minutes check never fired after a reboot. Now persisted
as LastOffenseAt FLOAT in UserState. On startup hydration, stale
offenses (and warned flag) are auto-cleared if the reset window has
passed. Bumped offense_reset_minutes from 2h to 24h.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-25 11:24:38 -05:00
parent 71c7b45e9a
commit 8734f1883b
4 changed files with 27 additions and 9 deletions

View File

@@ -913,6 +913,7 @@ class SentimentCog(commands.Cog):
baseline_coherence=user_data.baseline_coherence,
user_notes=user_data.notes or None,
warned=user_data.warned_since_reset,
last_offense_at=user_data.last_offense_time or None,
))
self._dirty_users.discard(user_id)
@@ -940,6 +941,7 @@ class SentimentCog(commands.Cog):
baseline_coherence=user_data.baseline_coherence,
user_notes=user_data.notes or None,
warned=user_data.warned_since_reset,
last_offense_at=user_data.last_offense_time or None,
)
logger.info("Flushed %d dirty user states to DB.", len(dirty))