diff --git a/cogs/chat.py b/cogs/chat.py index 598f82f..29d1ff0 100644 --- a/cogs/chat.py +++ b/cogs/chat.py @@ -1,6 +1,7 @@ import asyncio import logging import random +import re from collections import deque from pathlib import Path @@ -160,7 +161,13 @@ class ChatCog(commands.Cog): if typing_ctx: await typing_ctx.__aexit__(None, None, None) - if response is None: + # Strip leaked metadata the LLM may echo back + if response: + response = re.sub(r"\[Server context:[^\]]*\]\n?", "", response) + response = re.sub(r"\[Replying to bot's message:[^\]]*\]\n?", "", response) + response = response.strip() + + if not response: log_channel = discord.utils.get(message.guild.text_channels, name="bcs-log") if log_channel: try: