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:
13
cogs/chat.py
13
cogs/chat.py
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user