|
|
|
@ -444,7 +444,9 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
|
# Paginate and send the response back to the users
|
|
|
|
|
if not response_message:
|
|
|
|
|
if len(response_text) > self.TEXT_CUTOFF:
|
|
|
|
|
await self.paginate_and_send(response_text, message) # No paginations for multi-messages.
|
|
|
|
|
await self.paginate_and_send(
|
|
|
|
|
response_text, message
|
|
|
|
|
) # No paginations for multi-messages.
|
|
|
|
|
else:
|
|
|
|
|
response_message = await message.reply(
|
|
|
|
|
response_text.replace("<|endofstatement|>", ""),
|
|
|
|
@ -453,8 +455,12 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
|
self.redo_users[message.author.id] = RedoUser(
|
|
|
|
|
prompt, message, response_message
|
|
|
|
|
)
|
|
|
|
|
self.redo_users[message.author.id].add_interaction(response_message.id)
|
|
|
|
|
print(f"Added the interaction {response_message.id} to the redo user {message.author.id}")
|
|
|
|
|
self.redo_users[message.author.id].add_interaction(
|
|
|
|
|
response_message.id
|
|
|
|
|
)
|
|
|
|
|
print(
|
|
|
|
|
f"Added the interaction {response_message.id} to the redo user {message.author.id}"
|
|
|
|
|
)
|
|
|
|
|
original_message[message.author.id] = message.id
|
|
|
|
|
else:
|
|
|
|
|
# We have response_text available, this is the original message that we want to edit
|
|
|
|
@ -661,12 +667,15 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
|
# This is because encapsulated_send is a coroutine, and we need to await it to get the response from the model.
|
|
|
|
|
# We can't await it in the main thread, so we need to create a new thread to run it in.
|
|
|
|
|
# We can make sure that when the thread executes it executes in an async fashion by
|
|
|
|
|
asyncio.run_coroutine_threadsafe(self.encapsulated_send(
|
|
|
|
|
asyncio.run_coroutine_threadsafe(
|
|
|
|
|
self.encapsulated_send(
|
|
|
|
|
message,
|
|
|
|
|
prompt
|
|
|
|
|
if message.author.id not in self.conversating_users
|
|
|
|
|
else "".join(self.conversating_users[message.author.id].history),
|
|
|
|
|
), asyncio.get_running_loop())
|
|
|
|
|
),
|
|
|
|
|
asyncio.get_running_loop(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RedoView(discord.ui.View):
|
|
|
|
@ -696,18 +705,27 @@ class EndConvoButton(discord.ui.Button["RedoView"]):
|
|
|
|
|
|
|
|
|
|
# Get the user
|
|
|
|
|
user_id = interaction.user.id
|
|
|
|
|
if user_id in self.converser_cog.redo_users and self.converser_cog.redo_users[user_id].in_interaction(interaction.message.id):
|
|
|
|
|
if user_id in self.converser_cog.redo_users and self.converser_cog.redo_users[
|
|
|
|
|
user_id
|
|
|
|
|
].in_interaction(interaction.message.id):
|
|
|
|
|
try:
|
|
|
|
|
await self.converser_cog.end_conversation(self.converser_cog.redo_users[user_id].message)
|
|
|
|
|
await interaction.response.send_message("Your conversation has ended!", ephemeral=True,
|
|
|
|
|
delete_after=10)
|
|
|
|
|
await self.converser_cog.end_conversation(
|
|
|
|
|
self.converser_cog.redo_users[user_id].message
|
|
|
|
|
)
|
|
|
|
|
await interaction.response.send_message(
|
|
|
|
|
"Your conversation has ended!", ephemeral=True, delete_after=10
|
|
|
|
|
)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
await interaction.response.send_message(e, ephemeral=True, delete_after=30)
|
|
|
|
|
await interaction.response.send_message(
|
|
|
|
|
e, ephemeral=True, delete_after=30
|
|
|
|
|
)
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
await interaction.response.send_message("This is not your conversation to end!", ephemeral=True, delete_after=10)
|
|
|
|
|
await interaction.response.send_message(
|
|
|
|
|
"This is not your conversation to end!", ephemeral=True, delete_after=10
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RedoButton(discord.ui.Button["RedoView"]):
|
|
|
|
@ -719,7 +737,9 @@ class RedoButton(discord.ui.Button["RedoView"]):
|
|
|
|
|
|
|
|
|
|
# Get the user
|
|
|
|
|
user_id = interaction.user.id
|
|
|
|
|
if user_id in self.converser_cog.redo_users and self.converser_cog.redo_users[user_id].in_interaction(interaction.message.id):
|
|
|
|
|
if user_id in self.converser_cog.redo_users and self.converser_cog.redo_users[
|
|
|
|
|
user_id
|
|
|
|
|
].in_interaction(interaction.message.id):
|
|
|
|
|
# Get the message and the prompt and call encapsulated_send
|
|
|
|
|
message = self.converser_cog.redo_users[user_id].message
|
|
|
|
|
prompt = self.converser_cog.redo_users[user_id].prompt
|
|
|
|
@ -733,4 +753,8 @@ class RedoButton(discord.ui.Button["RedoView"]):
|
|
|
|
|
message, prompt, response_message
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
await interaction.response.send_message("You can only redo the most recent prompt that you sent yourself.", ephemeral=True, delete_after=10)
|
|
|
|
|
await interaction.response.send_message(
|
|
|
|
|
"You can only redo the most recent prompt that you sent yourself.",
|
|
|
|
|
ephemeral=True,
|
|
|
|
|
delete_after=10,
|
|
|
|
|
)
|
|
|
|
|