diff --git a/cogs/chat.py b/cogs/chat.py index 3c45ee1..93f1e74 100644 --- a/cogs/chat.py +++ b/cogs/chat.py @@ -205,12 +205,13 @@ class ChatCog(commands.Cog): await typing_ctx.__aexit__(None, None, None) # 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. + # The LLM often dumps paraphrased context and style labels in [brackets] + # before/between its actual answer. Split on those bracket lines and + # keep only the last non-empty segment — the real roast is always last. if response: - response = re.sub(r"^\s*\[[^\]]*\]\s*$", "", response, flags=re.MULTILINE) - response = re.sub(r"\n{2,}", "\n", response).strip() + segments = re.split(r"^\s*\[[^\]]*\]\s*$", response, flags=re.MULTILINE) + segments = [s.strip() for s in segments if s.strip()] + response = segments[-1] if segments else "" if not response: log_channel = discord.utils.get(message.guild.text_channels, name="bcs-log") @@ -317,10 +318,11 @@ class ChatCog(commands.Cog): recent_bot_replies=recent_bot_replies, ) - # Strip leaked metadata (same catch-all as main chat path) + # Strip leaked metadata (same approach as main chat path) if response: - response = re.sub(r"^\s*\[[^\]]*\]\s*$", "", response, flags=re.MULTILINE) - response = re.sub(r"\n{2,}", "\n", response).strip() + segments = re.split(r"^\s*\[[^\]]*\]\s*$", response, flags=re.MULTILINE) + segments = [s.strip() for s in segments if s.strip()] + response = segments[-1] if segments else "" if not response: return