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 <noreply@anthropic.com>
This commit is contained in:
2026-02-23 10:52:33 -05:00
parent 7743b22795
commit 431d63da72
2 changed files with 14 additions and 0 deletions

View File

@@ -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:

View File

@@ -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)