From e062cc2597d80964e486b313fdd4da50804c6ddb Mon Sep 17 00:00:00 2001 From: Rene Teigen Date: Sun, 1 Jan 2023 21:53:23 +0000 Subject: [PATCH] Fix view message edits --- cogs/draw_image_generation.py | 16 +++++++++------- cogs/gpt_3_commands_and_converser.py | 9 +++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cogs/draw_image_generation.py b/cogs/draw_image_generation.py index f23a206..efedc37 100644 --- a/cogs/draw_image_generation.py +++ b/cogs/draw_image_generation.py @@ -76,7 +76,7 @@ class DrawDallEService(commands.Cog, name="DrawDallEService"): ) await result_message.edit( - view=SaveView(image_urls, self, self.converser_cog, result_message) + view=SaveView(ctx, image_urls, self, self.converser_cog, result_message) ) self.converser_cog.users_to_interactions[user_id] = [] @@ -95,7 +95,7 @@ class DrawDallEService(commands.Cog, name="DrawDallEService"): file=file, ) await message.edit( - view=SaveView(image_urls, self, self.converser_cog, message) + view=SaveView(ctx, image_urls, self, self.converser_cog, message) ) else: # Varying case if not draw_from_optimizer: @@ -106,7 +106,7 @@ class DrawDallEService(commands.Cog, name="DrawDallEService"): ) await result_message.edit( view=SaveView( - image_urls, self, self.converser_cog, result_message, True + ctx, image_urls, self, self.converser_cog, result_message, True ) ) @@ -118,7 +118,7 @@ class DrawDallEService(commands.Cog, name="DrawDallEService"): ) await result_message.edit( view=SaveView( - image_urls, self, self.converser_cog, result_message + ctx, image_urls, self, self.converser_cog, result_message ) ) @@ -204,11 +204,12 @@ class DrawDallEService(commands.Cog, name="DrawDallEService"): class SaveView(discord.ui.View): def __init__( - self, image_urls, cog, converser_cog, message, no_retry=False, only_save=None + self, ctx, image_urls, cog, converser_cog, message, no_retry=False, only_save=None ): super().__init__( timeout=3600 if not only_save else None - ) # 10 minute timeout for Retry, Save + ) # 1 hour timeout for Retry, Save + self.ctx = ctx self.image_urls = image_urls self.cog = cog self.no_retry = no_retry @@ -234,6 +235,7 @@ class SaveView(discord.ui.View): # Create a new view with the same params as this one, but pass only_save=True new_view = SaveView( + self.ctx, self.image_urls, self.cog, self.converser_cog, @@ -243,7 +245,7 @@ class SaveView(discord.ui.View): ) # Set the view of the message to the new view - await self.message.edit(view=new_view) + await self.ctx.edit(view=new_view) class VaryButton(discord.ui.Button): diff --git a/cogs/gpt_3_commands_and_converser.py b/cogs/gpt_3_commands_and_converser.py index b5c549d..e54d8df 100644 --- a/cogs/gpt_3_commands_and_converser.py +++ b/cogs/gpt_3_commands_and_converser.py @@ -606,12 +606,12 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"): response_message = ( await ctx.respond( response_text, - view=RedoView(self, user_id), + view=RedoView(ctx, self, user_id), ) if from_context else await ctx.reply( response_text, - view=RedoView(self, user_id), + view=RedoView(ctx, self, user_id), ) ) @@ -868,9 +868,10 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"): class RedoView(discord.ui.View): - def __init__(self, converser_cog, user_id): + def __init__(self, ctx, converser_cog, user_id): super().__init__(timeout=3600) # 1 hour interval to redo. self.converser_cog = converser_cog + self.ctx = ctx self.add_item(RedoButton(self.converser_cog)) if user_id in self.converser_cog.conversating_users: @@ -880,7 +881,7 @@ class RedoView(discord.ui.View): # Remove the button from the view/message self.clear_items() # Send a message to the user saying the view has timed out - await self.message.edit( + await self.ctx.edit( view=None, )