From fc70fd5734ac2a52d00dcc09e0a58963b8bcaa0c Mon Sep 17 00:00:00 2001 From: Rene Teigen Date: Sun, 19 Feb 2023 13:47:13 +0000 Subject: [PATCH] Fix conversation limit thread closing logic for other users Return early on conversation processing if the conversation limit is reached --- cogs/text_service_cog.py | 10 ++++------ services/text_service.py | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cogs/text_service_cog.py b/cogs/text_service_cog.py index b7a6e95..6fffd1b 100644 --- a/cogs/text_service_cog.py +++ b/cogs/text_service_cog.py @@ -267,12 +267,8 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"): # If at conversation limit then fetch the owner and close the thread for them if conversation_limit: try: - owner_id = list(self.conversation_thread_owners.keys())[ - list( - [value for value in self.conversation_thread_owners.values()] - ).index(channel_id) - ] - self.conversation_thread_owners[normalized_user_id].remove( + owner_id = [owner for owner, threads in self.conversation_thread_owners.items() if channel_id in threads][0] + self.conversation_thread_owners[owner_id].remove( ctx.channel.id ) # Attempt to close and lock the thread. @@ -480,6 +476,8 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"): "You have reached the maximum conversation length. You have ended the conversation with GPT3, and it has ended." ) await self.end_conversation(message, conversation_limit=True) + return True + return False async def summarize_conversation(self, message, prompt): """Takes a conversation history filled prompt and summarizes it to then start a new history with it as the base""" diff --git a/services/text_service.py b/services/text_service.py index 9cca096..388a8d7 100644 --- a/services/text_service.py +++ b/services/text_service.py @@ -543,7 +543,8 @@ class TextService: prompt = await converser_cog.mention_to_username(message, content) - await converser_cog.check_conversation_limit(message) + if await converser_cog.check_conversation_limit(message): + return # If the user is in a conversation thread if message.channel.id in converser_cog.conversation_threads: