From 431d63da72d28147c858b85326fddba6df58c4f5 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 23 Feb 2026 10:52:33 -0500 Subject: [PATCH] Fix metadata leaking and skip sentiment for bot-directed messages 1. Broader regex to strip leaked metadata even when the LLM drops the "Server context:" prefix but keeps the content. 2. Skip sentiment analysis for messages that mention or reply to the bot. Users interacting with the bot in roast/chat modes shouldn't have those messages inflate their drama score. Co-Authored-By: Claude Opus 4.6 --- cogs/chat.py | 3 +++ cogs/sentiment.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/cogs/chat.py b/cogs/chat.py index 26151f7..ea1dc63 100644 --- a/cogs/chat.py +++ b/cogs/chat.py @@ -165,6 +165,8 @@ class ChatCog(commands.Cog): if response: response = re.sub(r"\[Server context:[^\]]*\]\n?", "", response) response = re.sub(r"\[Replying to bot's message:[^\]]*\]\n?", "", response) + # Catch reformatted metadata (LLM drops prefix but keeps content) + response = re.sub(r"\[[^\]]*#[a-z-]+[^\]]*(?:drama score|offense)[^\]]*\]\n?", "", response, flags=re.IGNORECASE) response = response.strip() if not response: @@ -274,6 +276,7 @@ class ChatCog(commands.Cog): response = re.sub(r"\[Server context:[^\]]*\]\n?", "", response) response = re.sub(r"\[.*?reacted to your message.*?\]\n?", "", response) response = re.sub(r"\[Your message was:.*?\]\n?", "", response) + response = re.sub(r"\[[^\]]*#[a-z-]+[^\]]*(?:drama score|offense)[^\]]*\]\n?", "", response, flags=re.IGNORECASE) response = response.strip() if not response: diff --git a/cogs/sentiment.py b/cogs/sentiment.py index 55e0ed5..0b836e1 100644 --- a/cogs/sentiment.py +++ b/cogs/sentiment.py @@ -80,6 +80,17 @@ class SentimentCog(commands.Cog): if self.bot.drama_tracker.is_immune(message.author.id): return + # Skip sentiment analysis for messages directed at the bot + # (mentions, replies to bot) — users interacting with the bot + # in roast/chat modes shouldn't have those messages scored as toxic + directed_at_bot = self.bot.user in message.mentions + if not directed_at_bot and message.reference and message.reference.message_id: + ref = message.reference.cached_message + if ref and ref.author.id == self.bot.user.id: + directed_at_bot = True + if directed_at_bot: + return + # Store message in channel history for context self._store_context(message)