From a46528ba90bd0d346c5ddd278881d0cbf87cde67 Mon Sep 17 00:00:00 2001 From: Rene Teigen Date: Wed, 11 Jan 2023 10:27:08 +0000 Subject: [PATCH] Add escape on mentions --- cogs/gpt_3_commands_and_converser.py | 2 ++ cogs/image_prompt_optimizer.py | 8 ++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cogs/gpt_3_commands_and_converser.py b/cogs/gpt_3_commands_and_converser.py index 6cc4c77..c1f1277 100644 --- a/cogs/gpt_3_commands_and_converser.py +++ b/cogs/gpt_3_commands_and_converser.py @@ -936,6 +936,8 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"): # If GPT3 tries to ping somebody, don't let it happen response_text = await self.replace_mention(ctx, response_text) + # escape any other metnions + response_text = discord.utils.escape_mentions(response_text) # If the user is conversing, add the GPT response to their conversation history. if ( diff --git a/cogs/image_prompt_optimizer.py b/cogs/image_prompt_optimizer.py index ffd1e99..0a08add 100644 --- a/cogs/image_prompt_optimizer.py +++ b/cogs/image_prompt_optimizer.py @@ -74,7 +74,7 @@ class ImgPromptOptimizer(discord.Cog, name="ImgPromptOptimizer"): user = ctx.user final_prompt = self.OPTIMIZER_PRETEXT - final_prompt += prompt + final_prompt += await self.converser_cog.replace_mention(ctx, prompt) # If the prompt doesn't end in a period, terminate it. if not final_prompt.endswith("."): @@ -101,11 +101,7 @@ class ImgPromptOptimizer(discord.Cog, name="ImgPromptOptimizer"): response_text = response["choices"][0]["text"] - if re.search(r"<@!?\d+>|<@&\d+>|<#\d+>", response_text): - await ctx.respond( - "I'm sorry, I can't mention users, roles, or channels." - ) - return + response_text = discord.utils.escape_mentions(response_text) response_message = await ctx.respond( response_text.replace("Optimized Prompt:", "")