diff --git a/cogs/chat.py b/cogs/chat.py index 870ceea..3c45ee1 100644 --- a/cogs/chat.py +++ b/cogs/chat.py @@ -204,16 +204,13 @@ class ChatCog(commands.Cog): if typing_ctx: await typing_ctx.__aexit__(None, None, None) - # Strip leaked metadata the LLM may echo back + # Strip leaked metadata the LLM may echo back. + # The LLM paraphrases/reformats injected context in unpredictable ways, + # so nuke any [bracketed block] that sits on its own line — real roasts + # don't use standalone bracketed text. if response: - response = re.sub(r"\[Server context:[^\]]*\]\n?", "", response) - response = re.sub(r"\[Replying to bot's message:[^\]]*\]\n?", "", response) - response = re.sub(r"\[\w[\w ]* said:[^\]]*\]\n?", "", response) - response = re.sub(r"\[Notes about [^\]]*\]\n?", "", response) - response = re.sub(r"\[[^\]]*'s recent messages:[\s\S]*?\]\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() + response = re.sub(r"^\s*\[[^\]]*\]\s*$", "", response, flags=re.MULTILINE) + response = re.sub(r"\n{2,}", "\n", response).strip() if not response: log_channel = discord.utils.get(message.guild.text_channels, name="bcs-log") @@ -320,13 +317,10 @@ class ChatCog(commands.Cog): recent_bot_replies=recent_bot_replies, ) - # Strip leaked metadata + # Strip leaked metadata (same catch-all as main chat path) if response: - 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() + response = re.sub(r"^\s*\[[^\]]*\]\s*$", "", response, flags=re.MULTILINE) + response = re.sub(r"\n{2,}", "\n", response).strip() if not response: return