Fix conversation limit not being able to close thread

Rene Teigen 2 years ago
parent 55f0db7f8b
commit 566484febf

@ -236,8 +236,11 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
return (cond1) and cond2 return (cond1) and cond2
async def end_conversation(self, ctx, opener_user_id=None): async def end_conversation(self, ctx, opener_user_id=None, conversation_limit=False):
normalized_user_id = opener_user_id if opener_user_id else ctx.author.id normalized_user_id = opener_user_id if opener_user_id else ctx.author.id
if conversation_limit: # if we reach the conversation limit we want to close from the channel it was maxed out in
channel_id = ctx.channel.id
else:
try: try:
channel_id = self.conversation_thread_owners[normalized_user_id] channel_id = self.conversation_thread_owners[normalized_user_id]
except: except:
@ -256,10 +259,27 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
) )
else: else:
await ctx.reply( await ctx.reply(
"You have ended the conversation with GPT3. Start a conversation with /gpt converse" "You have ended the conversation with GPT3. Start a conversation with /gpt converse", delete_after=10
) )
# Close all conversation threads for the user # Close all conversation threads for the user
# 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(self.conversation_thread_owners.values()).index(channel_id)]
self.conversation_thread_owners.pop(owner_id)
# Attempt to close and lock the thread.
try:
thread = await self.bot.fetch_channel(channel_id)
await thread.edit(locked=True)
await thread.edit(name="Closed-GPT")
except:
traceback.print_exc()
pass
except:
traceback.print_exc()
pass
else:
if normalized_user_id in self.conversation_thread_owners: if normalized_user_id in self.conversation_thread_owners:
thread_id = self.conversation_thread_owners[normalized_user_id] thread_id = self.conversation_thread_owners[normalized_user_id]
self.conversation_thread_owners.pop(normalized_user_id) self.conversation_thread_owners.pop(normalized_user_id)
@ -469,7 +489,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
await message.reply( await message.reply(
"You have reached the maximum conversation length. You have ended the conversation with GPT3, and it has ended." "You have reached the maximum conversation length. You have ended the conversation with GPT3, and it has ended."
) )
await self.end_conversation(message) await self.end_conversation(message, conversation_limit=True)
async def summarize_conversation(self, message, prompt): async def summarize_conversation(self, message, prompt):
response = await self.model.send_summary_request(prompt) response = await self.model.send_summary_request(prompt)

Loading…
Cancel
Save