From 615dd4a5efa45a31a91dd6c7a641e88c2ff514a2 Mon Sep 17 00:00:00 2001 From: koko210Serve Date: Mon, 23 Feb 2026 13:53:22 +0200 Subject: [PATCH] =?UTF-8?q?fix(P3):=203=20priority-3=20fixes=20=E2=80=94?= =?UTF-8?q?=20timezone,=20decay=20rounding,=20rate=20limiter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #16 Timezone consistency — added TZ=Europe/Sofia to docker-compose.yml so datetime.now() returns local time inside the container. Removed the +3 hour hack from get_time_of_day(). All three time-of-day consumers (autonomous_v1_legacy, moods, autonomous_engine) now use the same correct local hour automatically. #17 Decay truncation — replaced int() with round() in decay_events() so a counter of 1 survives one more 15-minute cycle instead of being immediately zeroed (round(0.841)=1 vs int(0.841)=0). #20 Unpersisted rate limiter — _last_action_execution dict in autonomous.py is now seeded from the engine's persisted server_last_action on import, so restarts don't bypass the 30-second cooldown. Note: #18 (dead config fields) was a false positive — autonomous_interval_minutes IS used by the scheduler. #19 deferred to bipolar mode rework. --- bot/utils/autonomous.py | 3 ++- bot/utils/autonomous_engine.py | 4 ++-- bot/utils/autonomous_v1_legacy.py | 2 +- docker-compose.yml | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bot/utils/autonomous.py b/bot/utils/autonomous.py index c725770..69c94fc 100644 --- a/bot/utils/autonomous.py +++ b/bot/utils/autonomous.py @@ -15,7 +15,8 @@ from utils.task_tracker import create_tracked_task logger = get_logger('autonomous') # Rate limiting: Track last action time per server to prevent rapid-fire -_last_action_execution = {} # guild_id -> timestamp +# Seeded from persisted engine data so restarts don't bypass cooldowns +_last_action_execution = dict(autonomous_engine.server_last_action) _MIN_ACTION_INTERVAL = 30 # Minimum 30 seconds between autonomous actions # Per-guild locks to prevent race conditions from near-simultaneous messages diff --git a/bot/utils/autonomous_engine.py b/bot/utils/autonomous_engine.py index 70d8a5c..29e7fc7 100644 --- a/bot/utils/autonomous_engine.py +++ b/bot/utils/autonomous_engine.py @@ -565,8 +565,8 @@ class AutonomousEngine: # Decay user events (half-life of 1 hour) # For 15-minute intervals: decay_factor = 0.5^(1/4) ≈ 0.841 decay_factor = 0.5 ** (1/4) # ≈ 0.8408964... - ctx.users_joined_recently = int(ctx.users_joined_recently * decay_factor) - ctx.users_status_changed = int(ctx.users_status_changed * decay_factor) + ctx.users_joined_recently = round(ctx.users_joined_recently * decay_factor) + ctx.users_status_changed = round(ctx.users_status_changed * decay_factor) # Clean up old activities (older than 1 hour) self._clean_old_activities(guild_id, max_age_seconds=3600) diff --git a/bot/utils/autonomous_v1_legacy.py b/bot/utils/autonomous_v1_legacy.py index 26d2c27..49847d9 100644 --- a/bot/utils/autonomous_v1_legacy.py +++ b/bot/utils/autonomous_v1_legacy.py @@ -682,7 +682,7 @@ def save_last_sent_tweets(): logger.error(f"Failed to save last sent tweets: {e}") def get_time_of_day(): - hour = datetime.now().hour + 3 + hour = datetime.now().hour if 5 <= hour < 12: return "morning" elif 12 <= hour < 18: diff --git a/docker-compose.yml b/docker-compose.yml index 2af4579..100ce38 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -109,6 +109,8 @@ services: miku-bot: build: ./bot container_name: miku-bot + environment: + - TZ=Europe/Sofia volumes: - ./bot/memory:/app/memory - /home/koko210Serve/ComfyUI/output:/app/ComfyUI/output:ro