From 6672bd2582b4708c326d8e5adf56b804bdc2c7d9 Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 19 Jul 2023 00:09:35 +0200 Subject: [PATCH 1/4] refactor(functionscalls.py): remove unnecessary print statements for image_url and json variables The print statements for the image_url and json variables were removed as they were not providing any useful information and were cluttering the code. --- src/functionscalls.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/functionscalls.py b/src/functionscalls.py index 0bcde64..7064fd7 100644 --- a/src/functionscalls.py +++ b/src/functionscalls.py @@ -205,10 +205,8 @@ async def send_a_gif( ): query = query.replace(" ", "+") image_url = f"{tenor_api_url}{query}&limit={limit}" - print(image_url) response = await do_async_request(image_url) json = response - print(json) gif_url = random.choice(json["results"])["itemurl"] # type: ignore message = message + "\n" + gif_url await message_in_channel_in_wich_to_send.channel.send(message) From 407cc40dbe7b9225b36a70ff85332964ef04e55a Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 19 Jul 2023 17:00:55 +0200 Subject: [PATCH 2/4] fix(openaicaller.py): improve error message when APIError occurs to clarify that it is OpenAI's fault and apologize for the inconvenience --- src/utils/openaicaller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/openaicaller.py b/src/utils/openaicaller.py index 9f7855d..57bcb93 100644 --- a/src/utils/openaicaller.py +++ b/src/utils/openaicaller.py @@ -123,7 +123,7 @@ class openai_caller: f"\n\n{bcolors.BOLD}{bcolors.WARNING}APIError. This is not your fault. Retrying...{bcolors.ENDC}" ) await recall_func( - "`An APIError occurred. This is not your fault. Retrying...`" + "`An APIError occurred. This is not your fault, it is OpenAI's fault. We apologize for the inconvenience. Retrying...`" ) await asyncio.sleep(10) await recall_func() From e1f9c91bde38b22eee91d900865caf6cccc30d71 Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 19 Jul 2023 19:51:05 +0200 Subject: [PATCH 3/4] refactor(main.py): change bot's presence activity to display the number of servers the bot is in feat(main.py): add event handler for on_guild_join to update bot's presence activity when joining a new server --- main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 20f7740..cf15e38 100644 --- a/main.py +++ b/main.py @@ -20,12 +20,21 @@ bot.add_cog(cogs.Moderation(bot)) async def on_ready(): await bot.change_presence( activity=discord.Activity( - type=discord.ActivityType.watching, name="your messages to answer you" + type=discord.ActivityType.watching, name=f"{len(bot.guilds)} servers" ) ) debug("Bot is ready") +@bot.event +async def on_guild_join(guild): + await bot.change_presence( + activity=discord.Activity( + type=discord.ActivityType.watching, name=f"{len(bot.guilds)} servers" + ) + ) + + @bot.event async def on_application_command_error(ctx, error): debug(error) From 19dd6c9c62725956308f715882e4203e5ed411f8 Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 2 Aug 2023 10:49:25 +0200 Subject: [PATCH 4/4] fix(makeprompt.py): fix issue where long response content is not fully sent in chatgpt_process function The issue was that when the response content was longer than 2000 characters, it was not being fully sent in the chatgpt_process function. This was fixed by adding a loop to send the content in chunks of 2000 characters until the entire content is sent. --- src/makeprompt.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/makeprompt.py b/src/makeprompt.py index 55f81e4..68a2cd5 100644 --- a/src/makeprompt.py +++ b/src/makeprompt.py @@ -169,6 +169,14 @@ async def chatgpt_process( "The function call is empty. Please retry.", delete_after=10 ) else: + content = response.get("content", "") + while len(content) != 0: + if len(content) > 2000: + await message.channel.send(content[:2000]) + content = content[2000:] + else: + await message.channel.send(content) + content = "" await message.channel.send(response["content"]) # type: ignore