Lower mute thresholds and order warnings before chat replies

- spike_mute: 0.8→0.7, mute: 0.75→0.65 so escalating users get
  timed out after a warning instead of endlessly warned
- Skip debounce on @mentions so sentiment analysis fires immediately
- Chat cog awaits pending sentiment analysis before replying,
  ensuring warnings/mutes appear before the personality response

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 14:16:34 -05:00
parent e2404d052c
commit 85ddba5e4b
3 changed files with 21 additions and 4 deletions

View File

@@ -1,3 +1,4 @@
import asyncio
import logging
from collections import deque
from pathlib import Path
@@ -125,6 +126,18 @@ class ChatCog(commands.Cog):
{"role": "assistant", "content": response}
)
# Wait for any pending sentiment analysis to finish first so
# warnings/mutes appear before the chat reply
sentiment_cog = self.bot.get_cog("SentimentCog")
if sentiment_cog:
key = (message.channel.id, message.author.id)
task = sentiment_cog._debounce_tasks.get(key)
if task and not task.done():
try:
await asyncio.wait_for(asyncio.shield(task), timeout=15)
except (asyncio.TimeoutError, asyncio.CancelledError):
pass
await message.reply(response, mention_author=False)
logger.info(
"Chat reply in #%s to %s: %s",

View File

@@ -96,8 +96,12 @@ class SentimentCog(commands.Cog):
if existing_task and not existing_task.done():
existing_task.cancel()
# Start new debounce timer
batch_window = config.get("sentiment", {}).get("batch_window_seconds", 3)
# Skip debounce when bot is @mentioned so warnings fire before chat replies
if self.bot.user in message.mentions:
batch_window = 0
else:
batch_window = config.get("sentiment", {}).get("batch_window_seconds", 3)
self._debounce_tasks[key] = asyncio.create_task(
self._debounce_then_process(key, batch_window)
)

View File

@@ -11,9 +11,9 @@ monitoring:
sentiment:
warning_threshold: 0.6
mute_threshold: 0.75
mute_threshold: 0.65
spike_warning_threshold: 0.5 # Single message score that triggers instant warning
spike_mute_threshold: 0.8 # Single message score that triggers instant mute
spike_mute_threshold: 0.7 # Single message score that triggers instant mute
context_messages: 8 # Number of previous messages to include as context
rolling_window_size: 10 # Number of messages to track per user
rolling_window_minutes: 15 # Time window for tracking