diff --git a/cogs/chat.py b/cogs/chat.py index cdef9d9..3379180 100644 --- a/cogs/chat.py +++ b/cogs/chat.py @@ -55,7 +55,7 @@ class ChatCog(commands.Cog): if self.bot.user in message.mentions: should_reply = True - # Check if replying to one of the bot's messages + # Check if replying to a message if message.reference and message.reference.message_id: try: ref_msg = message.reference.cached_message @@ -64,9 +64,14 @@ class ChatCog(commands.Cog): message.reference.message_id ) if ref_msg.author.id == self.bot.user.id: + # Replying to the bot's own message — continue conversation should_reply = True if ref_msg.content: reply_context = f"[Replying to bot's message: {ref_msg.content[:300]}]\n" + elif should_reply: + # @mentioned the bot while replying to someone else — include that message + ref_text = ref_msg.content[:500] if ref_msg.content else "(no text)" + reply_context = f"[{ref_msg.author.display_name} said: {ref_text}]\n" except discord.HTTPException: pass @@ -99,13 +104,25 @@ class ChatCog(commands.Cog): # Clean the mention out of the message content content = message.content.replace(f"<@{self.bot.user.id}>", "").strip() - # Check for image attachments + # Check for image attachments (on this message or the referenced message) image_attachment = None for att in message.attachments: ext = att.filename.rsplit(".", 1)[-1].lower() if "." in att.filename else "" if ext in _IMAGE_TYPES: image_attachment = att break + if not image_attachment and message.reference: + try: + ref = message.reference.cached_message or await message.channel.fetch_message( + message.reference.message_id + ) + for att in ref.attachments: + ext = att.filename.rsplit(".", 1)[-1].lower() if "." in att.filename else "" + if ext in _IMAGE_TYPES: + image_attachment = att + break + except discord.HTTPException: + pass typing_ctx = None @@ -165,6 +182,7 @@ 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) + response = re.sub(r"\[\w[\w ]* said:[^\]]*\]\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()