From b14086fdab774999c531b4704fcb108da82d2788 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sat, 26 Nov 2022 20:26:30 +0100 Subject: [PATCH 001/131] Update README.md --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 252cb16..f68370d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ # Botator - A discord bot to connect openai's gpt-3 davinci-002 model to a discord channel. +Botator is a discord bot that binds openai's gpt3 AI with discord. You will be able to take the conversation with the AI into a specific channel that you created. +[discord com_channels_1021872219888033903_1046119234033434734](https://user-images.githubusercontent.com/75439456/204105583-2abb2d77-9404-4558-bd3e-c1a70b939758.png) + +# Adding the bot to your discord server +In order to add the bot to your discord server, you will need an OpenAI API key. You can create an account and take one here: https://beta.openai.com/account/api-keys +You can add the bot to your server by clcking onto the following link: +https://discord.com/api/oauth2/authorize?client_id=1046051875755134996&permissions=2214808576&scope=applications.commands%20bot +Then, run the following commands to set your bot up: +First /setchannel and select the channel where you want the bot to talk. +Then /setkey and put in your openai api key. +You can now enable your bot by doing /enable. +You can always disable the bot by doing /disable and delete your api key & channel by doing /delete. From 5b8e83e5a2fc0612b2986fb50580a272701b6bce Mon Sep 17 00:00:00 2001 From: Paillat Date: Sat, 26 Nov 2022 20:28:51 +0100 Subject: [PATCH 002/131] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f68370d..eba2ff5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Botator Botator is a discord bot that binds openai's gpt3 AI with discord. You will be able to take the conversation with the AI into a specific channel that you created. -[discord com_channels_1021872219888033903_1046119234033434734](https://user-images.githubusercontent.com/75439456/204105583-2abb2d77-9404-4558-bd3e-c1a70b939758.png) +![discord com_channels_1021872219888033903_1046119234033434734](https://user-images.githubusercontent.com/75439456/204105583-2abb2d77-9404-4558-bd3e-c1a70b939758.png) # Adding the bot to your discord server In order to add the bot to your discord server, you will need an OpenAI API key. You can create an account and take one here: https://beta.openai.com/account/api-keys From b9bcf502c5e3ca774620c578f828bafa772852fd Mon Sep 17 00:00:00 2001 From: Paillat Date: Sat, 26 Nov 2022 20:30:17 +0100 Subject: [PATCH 003/131] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index eba2ff5..2bddb4b 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,8 @@ Botator is a discord bot that binds openai's gpt3 AI with discord. You will be a ![discord com_channels_1021872219888033903_1046119234033434734](https://user-images.githubusercontent.com/75439456/204105583-2abb2d77-9404-4558-bd3e-c1a70b939758.png) # Adding the bot to your discord server -In order to add the bot to your discord server, you will need an OpenAI API key. You can create an account and take one here: https://beta.openai.com/account/api-keys -You can add the bot to your server by clcking onto the following link: -https://discord.com/api/oauth2/authorize?client_id=1046051875755134996&permissions=2214808576&scope=applications.commands%20bot +In order to add the bot to your discord server, you will need an OpenAI API key. You can create an account and take one [here](https://beta.openai.com/account/api-keys) +You can add the bot to your server by clcking [here](https://discord.com/api/oauth2/authorize?client_id=1046051875755134996&permissions=2214808576&scope=applications.commands%20bot) Then, run the following commands to set your bot up: First /setchannel and select the channel where you want the bot to talk. Then /setkey and put in your openai api key. From f7fda5fc715544bdb8cbdead80b86a28e97e7b5c Mon Sep 17 00:00:00 2001 From: Paillat Date: Sat, 26 Nov 2022 20:31:28 +0100 Subject: [PATCH 004/131] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2bddb4b..6a3a3b6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Botator is a discord bot that binds openai's gpt3 AI with discord. You will be a In order to add the bot to your discord server, you will need an OpenAI API key. You can create an account and take one [here](https://beta.openai.com/account/api-keys) You can add the bot to your server by clcking [here](https://discord.com/api/oauth2/authorize?client_id=1046051875755134996&permissions=2214808576&scope=applications.commands%20bot) Then, run the following commands to set your bot up: -First /setchannel and select the channel where you want the bot to talk. -Then /setkey and put in your openai api key. -You can now enable your bot by doing /enable. -You can always disable the bot by doing /disable and delete your api key & channel by doing /delete. +First **/setchannel** and select the channel where you want the bot to talk. +Then **/setkey** and put in your openai api key. +You can now enable your bot by doing **/enable**. +You can always disable the bot by doing **/disable** and delete your api key & channel from our servers by doing **/delete**. From 6282262c139c9f0a67ced361f9ea63546e7ea523 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sat, 26 Nov 2022 20:32:10 +0100 Subject: [PATCH 005/131] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6a3a3b6..52b80fe 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,6 @@ In order to add the bot to your discord server, you will need an OpenAI API key You can add the bot to your server by clcking [here](https://discord.com/api/oauth2/authorize?client_id=1046051875755134996&permissions=2214808576&scope=applications.commands%20bot) Then, run the following commands to set your bot up: First **/setchannel** and select the channel where you want the bot to talk. -Then **/setkey** and put in your openai api key. -You can now enable your bot by doing **/enable**. -You can always disable the bot by doing **/disable** and delete your api key & channel from our servers by doing **/delete**. +\nThen **/setkey** and put in your openai api key. +\nYou can now enable your bot by doing **/enable**. +\nYou can always disable the bot by doing **/disable** and delete your api key & channel from our servers by doing **/delete**. From e68ac704060a6f1803805d973bb260ce17b084ed Mon Sep 17 00:00:00 2001 From: Paillat Date: Sat, 26 Nov 2022 20:33:14 +0100 Subject: [PATCH 006/131] Update README.md --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 52b80fe..8347875 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,15 @@ Botator is a discord bot that binds openai's gpt3 AI with discord. You will be a # Adding the bot to your discord server In order to add the bot to your discord server, you will need an OpenAI API key. You can create an account and take one [here](https://beta.openai.com/account/api-keys) + You can add the bot to your server by clcking [here](https://discord.com/api/oauth2/authorize?client_id=1046051875755134996&permissions=2214808576&scope=applications.commands%20bot) + Then, run the following commands to set your bot up: + First **/setchannel** and select the channel where you want the bot to talk. -\nThen **/setkey** and put in your openai api key. -\nYou can now enable your bot by doing **/enable**. -\nYou can always disable the bot by doing **/disable** and delete your api key & channel from our servers by doing **/delete**. + +Then **/setkey** and put in your openai api key. + +You can now enable your bot by doing **/enable**. + +You can always disable the bot by doing **/disable** and delete your api key & channel from our servers by doing **/delete**. From 7c3482fecf4655c6800ae220c4538fb42b651f55 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sat, 26 Nov 2022 20:33:45 +0100 Subject: [PATCH 007/131] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8347875..095f640 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,4 @@ Then **/setkey** and put in your openai api key. You can now enable your bot by doing **/enable**. -You can always disable the bot by doing **/disable** and delete your api key & channel from our servers by doing **/delete**. +You can always disable the bot by doing **/disable** and delete your api key & channel from our server by doing **/delete**. From 7b6d85414f3e2c720792b38d120a1da3a5f63fc2 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sat, 26 Nov 2022 20:37:11 +0100 Subject: [PATCH 008/131] Delete database.db --- code/database.db | Bin 8192 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 code/database.db diff --git a/code/database.db b/code/database.db deleted file mode 100644 index 2a03da1a04b78c3ee10e9d0ad185a7a9f2ac7e53..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmeI#PfNov7zXfUOvHoC%kY|`f=b%dwY}N>QPIJy_Tt5nZmFxS-B`0R3m*Iup7&90 z(aobbPtQYMc=IL@_}%j0_hYSCG@ZXn%>+3hl#&a^2qE>dYGrLg%ch!bQtkgrotzEc z_sd(f@kz>sKmY;|fB*y_009U<00Izz00bbg6`0W7!)B9y2ra`@jir`V)jIb*FX*wr zYxjGsny{niMVyX@@tA3~(kE;*ky)nF-+`RP!$iIP9LM=kj&!_KESyeLC9~u2zxkRp z*4xL?KmY;|fB*y_009U<00Izz00bcL&jL?$M~HmS;HKf&rfIm2<8UEdF3OQUq%&3 ALI3~& From 33995769885cb7b98b2508ba0e7048c5fdbc2764 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sat, 26 Nov 2022 20:58:10 +0100 Subject: [PATCH 009/131] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 095f640..25f5735 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ First **/setchannel** and select the channel where you want the bot to talk. Then **/setkey** and put in your openai api key. +Please note that we can possibly log the messages that are sent for **no more than 24h**, and that we will store your openai API key. Ypu can delete your API key from our servers by doing **/delete**. Please note that this action is irreversible. + You can now enable your bot by doing **/enable**. -You can always disable the bot by doing **/disable** and delete your api key & channel from our server by doing **/delete**. +You can always disable the bot by doing **/disable** and delete your api key from our server by doing **/delete**. From df5dc1536e90d1fec60bb72d5bbb4f44ce3b6981 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 16:10:09 +0100 Subject: [PATCH 010/131] . --- database/{data.db => old database.db} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename database/{data.db => old database.db} (100%) diff --git a/database/data.db b/database/old database.db similarity index 100% rename from database/data.db rename to database/old database.db From 9779707427d8ed1883754001c36868665c24b859 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 16:24:43 +0100 Subject: [PATCH 011/131] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 25f5735..9cde754 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ You can add the bot to your server by clcking [here](https://discord.com/api/oau Then, run the following commands to set your bot up: -First **/setchannel** and select the channel where you want the bot to talk. +First **/setup**, define the channel you want the bot to talk into and your OPENAI api key. -Then **/setkey** and put in your openai api key. +Then, if you want, **/advanced** to define some more advanced parameters.. -Please note that we can possibly log the messages that are sent for **no more than 24h**, and that we will store your openai API key. Ypu can delete your API key from our servers by doing **/delete**. Please note that this action is irreversible. +Please note that we can possibly log the messages that are sent for **no more than 24h**, and that we will store your openai API key. You can always delete your API key from our servers by doing **/delete**. Please note that this action is irreversible. You can now enable your bot by doing **/enable**. From 47ec9ffd8b73ac1e631ff7dc739f647eec20bc44 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 16:29:15 +0100 Subject: [PATCH 012/131] Do not remove uses_count_today from the database --- code/code.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/code/code.py b/code/code.py index ec525d4..a376f49 100644 --- a/code/code.py +++ b/code/code.py @@ -6,6 +6,7 @@ import sqlite3 # pip install sqlite3 import asyncio # pip install asyncio #set the debug mode to the maximum logging.basicConfig(level=logging.INFO) + def debug(message): logging.info(message) @@ -101,8 +102,8 @@ async def delete(ctx): if c.fetchone() is None: await ctx.respond("This server is not setup", ephemeral=True) return - #delete the guild from the database - c.execute("DELETE FROM data WHERE guild_id = ?", (ctx.guild.id,)) + #delete the guild from the database, except the guild id and the uses_count_today + c.execute("UPDATE data SET api_key = ?, channel_id = ?, is_active = ?, max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (None, None, False, 50, 0.9, 0.0, 0.0, 0, ctx.guild.id)) conn.commit() await ctx.send("The guild has been deleted from the database") @bot.command() @@ -116,6 +117,7 @@ async def help(ctx): embed.add_field(name="/help", value="Show this message", inline=False) await ctx.respond(embed=embed, ephemeral=True) #when a message is sent into a channel check if the guild is in the database and if the bot is enabled + @bot.event async def on_message(message): #check if the message is from a bot @@ -178,6 +180,8 @@ async def on_message(message): #get the message content # add a slash command called "say" that sends a message to the channel +''' +#these are debug commands and should not be used in production @bot.slash_command() async def say(ctx, message: str): await ctx.respond("message sent!", ephemeral=True) @@ -187,7 +191,7 @@ async def say(ctx, message: str): async def clear(ctx): await ctx.respond("messages deleted!", ephemeral=True) return await ctx.channel.purge() - +''' #at the end of the day reset the uses_count_today to 0 for all the guilds async def reset_uses_count_today(): await bot.wait_until_ready() From a974472e239d1032feaa5cb7e6260cd8ff8cb035 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 16:35:19 +0100 Subject: [PATCH 013/131] Update code.py --- code/code.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/code.py b/code/code.py index a376f49..ca627ca 100644 --- a/code/code.py +++ b/code/code.py @@ -139,6 +139,8 @@ async def on_message(message): #check if the bot hasn't been used more than 200 times in the last 24 hours (uses_count_today) c.execute("SELECT uses_count_today FROM data WHERE guild_id = ?", (message.guild.id,)) if c.fetchone()[0] >= 200: + debug("The bot has been used more than 200 times in the last 24 hours in this guild") + await message.channel.send("The bot has been used more than 200 times in the last 24 hours in this guild. Please try again in 24h.") return #add 1 to the uses_count_today c.execute("UPDATE data SET uses_count_today = uses_count_today + 1 WHERE guild_id = ?", (message.guild.id,)) From c90ccfacf40c6e203c6c94286d81c3fb4af8e388 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 16:39:10 +0100 Subject: [PATCH 014/131] Disabled voice capabilityes --- docker/Build/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Build/requirements.txt b/docker/Build/requirements.txt index a85e613..80f6c11 100644 --- a/docker/Build/requirements.txt +++ b/docker/Build/requirements.txt @@ -1,3 +1,3 @@ # To ensure app dependencies are ported from your virtual environment/host machine into your container, run 'pip freeze > requirements.txt' in the terminal to overwrite this file -py-cord[voice] +py-cord openai From 986ee2e39123f75a2c4f9bbbf23b3bff6de92ea1 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 16:46:15 +0100 Subject: [PATCH 015/131] Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 9cde754..42c5994 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,12 @@ Please note that we can possibly log the messages that are sent for **no more th You can now enable your bot by doing **/enable**. You can always disable the bot by doing **/disable** and delete your api key from our server by doing **/delete**. + +# Docker +You can run this bot with docker. First clone this repository, then run the following command in the /Botator/docker/Build directory. + +`docker build . -t botator:latest --no-cache` + +You cann then run the contaier with this command: + +`docker run -d --name botatordef -v ./botator/:/Botator/database botator:latest` From dae8c0148513ee9432f0a07da767245d3536ece9 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 16:49:28 +0100 Subject: [PATCH 016/131] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 42c5994..ed239bb 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,10 @@ You can now enable your bot by doing **/enable**. You can always disable the bot by doing **/disable** and delete your api key from our server by doing **/delete**. # Docker -You can run this bot with docker. First clone this repository, then run the following command in the /Botator/docker/Build directory. +You can run this bot with docker. First clone this repository. Now replace the text into the key.txt file that you will find into the ./Botator/docker/Build directory with your **DISCORD** API key. After that,run the following command in the /Botator/docker/Build directory. `docker build . -t botator:latest --no-cache` -You cann then run the contaier with this command: +Now create a directory called `botator` where you want the database files to be stored, and run the following command into that directory to run the container. -`docker run -d --name botatordef -v ./botator/:/Botator/database botator:latest` +`docker run -d --name botatordef -v ./:/Botator/database botator:latest` From f1a1d00b963cc8774b1524ac31e2de8971309c21 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 16:57:10 +0100 Subject: [PATCH 017/131] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed239bb..dc7e5e9 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,4 @@ You can run this bot with docker. First clone this repository. Now replace the t Now create a directory called `botator` where you want the database files to be stored, and run the following command into that directory to run the container. -`docker run -d --name botatordef -v ./:/Botator/database botator:latest` +`docker run -d --name botatordef -v **your botator folder directory**:/Botator/database botator:latest` From d5d23d55bf671468fd7a2f73a91ac9ab764df3d9 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 16:57:49 +0100 Subject: [PATCH 018/131] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dc7e5e9..7d6c9c4 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,4 @@ You can run this bot with docker. First clone this repository. Now replace the t Now create a directory called `botator` where you want the database files to be stored, and run the following command into that directory to run the container. -`docker run -d --name botatordef -v **your botator folder directory**:/Botator/database botator:latest` +`docker run -d --name botatordef -v `**`your botator folder directory`**`:/Botator/database botator:latest` From 4f569d1b071dc1b8b2a9b486732e0449d822d407 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 16:58:30 +0100 Subject: [PATCH 019/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index ca627ca..591243a 100644 --- a/code/code.py +++ b/code/code.py @@ -83,7 +83,7 @@ async def disable(ctx): @discord.commands.option(name="presence_penalty", description="The presence penalty", required=False) #set the fifth argument: prompt_size, with a default value of 5 @discord.commands.option(name="prompt_size", description="The number of messages to use as a prompt", required=False) -async def advanced(ctx, max_tokens=256, temperature=0.9, frequency_penalty=0, presence_penalty=0.6, prompt_size=5): +async def advanced(ctx, max_tokens=256, temperature=1, frequency_penalty=0, presence_penalty=0.6, prompt_size=5): #check if the guild is in the database c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) if c.fetchone() is None: From 18318c4aa064a04057213f3a17f4ae1ff7122e1a Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 17:09:52 +0100 Subject: [PATCH 020/131] Added transcript command. --- code/code.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/code/code.py b/code/code.py index 591243a..5f4e701 100644 --- a/code/code.py +++ b/code/code.py @@ -4,6 +4,7 @@ from discord import File, Intents # pip install pycord import logging # pip install logging import sqlite3 # pip install sqlite3 import asyncio # pip install asyncio +import os # pip install os #set the debug mode to the maximum logging.basicConfig(level=logging.INFO) @@ -43,7 +44,7 @@ async def setup(ctx, channel: discord.TextChannel, api_key): #add the guild to the database c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 50, 0.9, 0.0, 0.0, 0, 0)) conn.commit() - await ctx.send("The guild has been added to the database") + await ctx.respond("Setup complete", ephemeral=True) #create a command called "enable" taht only admins can use @bot.command() ##@discord.commands.permissions(administrator=True) @@ -56,7 +57,7 @@ async def enable(ctx): #enable the guild c.execute("UPDATE data SET is_active = ? WHERE guild_id = ?", (True, ctx.guild.id)) conn.commit() - await ctx.send("The guild has been enabled") + await ctx.respond("Enabled", ephemeral=True) #create a command called "disable" that only admins can use @bot.command() ##@discord.commands.permissions(administrator=True) @@ -69,7 +70,7 @@ async def disable(ctx): #disable the guild c.execute("UPDATE data SET is_active = ? WHERE guild_id = ?", (False, ctx.guild.id)) conn.commit() - await ctx.send("The guild has been disabled") + await ctx.respond("Disabled", ephemeral=True) #create a command called "advanced" that only admins can use, wich sets the advanced settings up: max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size @bot.command() ##@discord.commands.permissions(administrator=True) @@ -105,7 +106,7 @@ async def delete(ctx): #delete the guild from the database, except the guild id and the uses_count_today c.execute("UPDATE data SET api_key = ?, channel_id = ?, is_active = ?, max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (None, None, False, 50, 0.9, 0.0, 0.0, 0, ctx.guild.id)) conn.commit() - await ctx.send("The guild has been deleted from the database") + await ctx.respond("Deleted", ephemeral=True) @bot.command() async def help(ctx): embed = discord.Embed(title="Help", description="Here is the help page", color=0x00ff00) @@ -182,6 +183,27 @@ async def on_message(message): #get the message content # add a slash command called "say" that sends a message to the channel +@bot.command() +async def transcript(ctx): +#save all the messages in the channel in a txt file and send it + messages = await ctx.channel.history(limit=None).flatten() + messages.reverse() + transcript = "" + #defer the response + await ctx.defer() + for msg in messages: + if msg.author.bot: + transcript += f"AI: {msg.content}\n" + else: + transcript += f"{msg.author.display_name}: {msg.content}\n" +#save the transcript in a txt file called transcript.txt. If the file already exists, delete it and create a new one +#check if the file exists + if os.path.exists("transcript.txt"): + os.remove("transcript.txt") + f = open("transcript.txt", "w") + f.write(transcript) + f.close() + await ctx.respond(file=discord.File("transcript.txt")) ''' #these are debug commands and should not be used in production @bot.slash_command() @@ -194,7 +216,6 @@ async def clear(ctx): await ctx.respond("messages deleted!", ephemeral=True) return await ctx.channel.purge() ''' -#at the end of the day reset the uses_count_today to 0 for all the guilds async def reset_uses_count_today(): await bot.wait_until_ready() while not bot.is_closed(): From 0054f51d3cb8f80d217650124750735a34563065 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 17:11:58 +0100 Subject: [PATCH 021/131] added os --- docker/Build/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/Build/requirements.txt b/docker/Build/requirements.txt index 80f6c11..68cbe8d 100644 --- a/docker/Build/requirements.txt +++ b/docker/Build/requirements.txt @@ -1,3 +1,4 @@ # To ensure app dependencies are ported from your virtual environment/host machine into your container, run 'pip freeze > requirements.txt' in the terminal to overwrite this file py-cord openai +os From a8fde1d7a3656911edcd2d0d37bcc78a3a9aa77f Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 17:12:50 +0100 Subject: [PATCH 022/131] removed os --- docker/Build/requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/Build/requirements.txt b/docker/Build/requirements.txt index 68cbe8d..80f6c11 100644 --- a/docker/Build/requirements.txt +++ b/docker/Build/requirements.txt @@ -1,4 +1,3 @@ # To ensure app dependencies are ported from your virtual environment/host machine into your container, run 'pip freeze > requirements.txt' in the terminal to overwrite this file py-cord openai -os From c72df5417d049fe33ed408a41b0611cdf78be011 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 20:15:23 +0100 Subject: [PATCH 023/131] Added /info command --- code/code.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/code/code.py b/code/code.py index 5f4e701..2a5142f 100644 --- a/code/code.py +++ b/code/code.py @@ -118,6 +118,30 @@ async def help(ctx): embed.add_field(name="/help", value="Show this message", inline=False) await ctx.respond(embed=embed, ephemeral=True) #when a message is sent into a channel check if the guild is in the database and if the bot is enabled +@bot.command() +async def info(ctx): + #this command sends all the data about the guild, including the api key, the channel id, the advanced settings and the uses_count_today + #check if the guild is in the database + c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) + if c.fetchone() is None: + await ctx.respond("This server is not setup", ephemeral=True) + return + #get all the data from the database + c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) + data = c.fetchone() + #send the data + embed = discord.Embed(title="Info", description="Here is the info page", color=0x00ff00) + embed.add_field(name="guild_id", value=data[0], inline=False) + embed.add_field(name="API Key", value=data[1], inline=False) + embed.add_field(name="Channel ID", value=data[2], inline=False) + embed.add_field(name="Is Active", value=data[3], inline=False) + embed.add_field(name="Max Tokens", value=data[4], inline=False) + embed.add_field(name="Temperature", value=data[5], inline=False) + embed.add_field(name="Frequency Penalty", value=data[6], inline=False) + embed.add_field(name="Presence Penalty", value=data[7], inline=False) + embed.add_field(name="Prompt Size", value=data[8], inline=False) + embed.add_field(name="Uses Count Today", value=data[9], inline=False) + await ctx.respond(embed=embed, ephemeral=True) @bot.event async def on_message(message): From 062ecd8121b591dc421207f1885c83e032ae283f Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 20:34:01 +0100 Subject: [PATCH 024/131] Debugged --- code/code.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/code/code.py b/code/code.py index 2a5142f..79f3cdb 100644 --- a/code/code.py +++ b/code/code.py @@ -5,6 +5,7 @@ import logging # pip install logging import sqlite3 # pip install sqlite3 import asyncio # pip install asyncio import os # pip install os + #set the debug mode to the maximum logging.basicConfig(level=logging.INFO) @@ -17,7 +18,7 @@ c = conn.cursor() # Create table called "data" if it does not exist with the following columns: guild_id, channel_id, api_key, is_active, max_tokens, temperature, frequency_penalty, presence_penalty, uses_count_today, prompt_size c.execute('''CREATE TABLE IF NOT EXISTS data (guild_id text, channel_id text, api_key text, is_active boolean, max_tokens integer, temperature real, frequency_penalty real, presence_penalty real, uses_count_today integer, prompt_size integer)''') -Intents =discord.Intents.all() # enable all intents +Intents=discord.Intents.all() # enable all intents Intents.members = True bot = discord.Bot(intents=Intents.all()) #create a command called "setup" that takes 2 arguments: the channel id and the api key @@ -42,7 +43,7 @@ async def setup(ctx, channel: discord.TextChannel, api_key): await ctx.respond("This server is already setup", ephemeral=True) return #add the guild to the database - c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 50, 0.9, 0.0, 0.0, 0, 0)) + c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 150, 1, 0, 0.6, 0, 5)) conn.commit() await ctx.respond("Setup complete", ephemeral=True) #create a command called "enable" taht only admins can use @@ -76,7 +77,7 @@ async def disable(ctx): ##@discord.commands.permissions(administrator=True) #set the first argument: max_tokens, with a default value of 150 @discord.commands.option(name="max_tokens", description="The max tokens", required=False) -#set the second argument: temperature, with a default value of 0.5 +#set the second argument: temperature, with a default value of 1 @discord.commands.option(name="temperature", description="The temperature", required=False) #set the third argument: frequency_penalty, with a default value of 0.5 @discord.commands.option(name="frequency_penalty", description="The frequency penalty", required=False) From 668fcbff5978a9e97f8680d49852a7ca45a7dd7f Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 20:44:25 +0100 Subject: [PATCH 025/131] Debugged --- code/code.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/code.py b/code/code.py index 79f3cdb..a313740 100644 --- a/code/code.py +++ b/code/code.py @@ -37,12 +37,12 @@ async def setup(ctx, channel: discord.TextChannel, api_key): if channel is None: await ctx.respond("Invalid channel id", ephemeral=True) return - #check if the guild is already in the database + #check if the guild is already in the database bi checking if there is a key for the guild c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) - if c.fetchone() is not None: - await ctx.respond("This server is already setup", ephemeral=True) + if c.fetchone()[2] is not None: + await ctx.respond("This guild is already setup", ephemeral=True) return - #add the guild to the database + #add the guild to the database c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 150, 1, 0, 0.6, 0, 5)) conn.commit() await ctx.respond("Setup complete", ephemeral=True) From 5db0ea9ee0d40eddce343810b9c047fed24d6a2a Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 20:54:36 +0100 Subject: [PATCH 026/131] Debugged --- code/code.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/code/code.py b/code/code.py index a313740..4b33018 100644 --- a/code/code.py +++ b/code/code.py @@ -39,13 +39,18 @@ async def setup(ctx, channel: discord.TextChannel, api_key): return #check if the guild is already in the database bi checking if there is a key for the guild c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) - if c.fetchone()[2] is not None: - await ctx.respond("This guild is already setup", ephemeral=True) - return - #add the guild to the database - c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 150, 1, 0, 0.6, 0, 5)) - conn.commit() - await ctx.respond("Setup complete", ephemeral=True) + if c.fetchone() is not None: + #in this case, the guild is already in the database, so we update the channel id and the api key + c.execute("UPDATE data SET channel_id = ?, api_key = ? WHERE guild_id = ?", (channel.id, api_key, ctx.guild.id)) + #we will also set the advanced settings to their default values + c.execute("UPDATE data SET is_active = ?, max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, uses_count_today = ?, prompt_size = ? WHERE guild_id = ?", (False, 64, 0.9, 0.0, 0.0, 0, 5, ctx.guild.id)) + conn.commit() + await ctx.respond("The channel id and the api key have been updated", ephemeral=True) + else: + #in this case, the guild is not in the database, so we add it + c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 64, 0.9, 0.0, 0.0, 0, 5)) + conn.commit() + await ctx.respond("The channel id and the api key have been added", ephemeral=True) #create a command called "enable" taht only admins can use @bot.command() ##@discord.commands.permissions(administrator=True) From c10299db689608e3d576b0c4a506e8709d1bbb86 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 27 Nov 2022 21:00:05 +0100 Subject: [PATCH 027/131] Debugged --- code/code.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/code.py b/code/code.py index 4b33018..ecfddac 100644 --- a/code/code.py +++ b/code/code.py @@ -43,12 +43,12 @@ async def setup(ctx, channel: discord.TextChannel, api_key): #in this case, the guild is already in the database, so we update the channel id and the api key c.execute("UPDATE data SET channel_id = ?, api_key = ? WHERE guild_id = ?", (channel.id, api_key, ctx.guild.id)) #we will also set the advanced settings to their default values - c.execute("UPDATE data SET is_active = ?, max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, uses_count_today = ?, prompt_size = ? WHERE guild_id = ?", (False, 64, 0.9, 0.0, 0.0, 0, 5, ctx.guild.id)) + c.execute("UPDATE data SET is_active = ?, max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (False, 64, 0.9, 0.0, 0.0, 5, ctx.guild.id)) conn.commit() await ctx.respond("The channel id and the api key have been updated", ephemeral=True) else: #in this case, the guild is not in the database, so we add it - c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 64, 0.9, 0.0, 0.0, 0, 5)) + c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, api_key, channel.id, False, 64, 0.9, 0.0, 0.0, 0, 5)) conn.commit() await ctx.respond("The channel id and the api key have been added", ephemeral=True) #create a command called "enable" taht only admins can use @@ -138,8 +138,8 @@ async def info(ctx): #send the data embed = discord.Embed(title="Info", description="Here is the info page", color=0x00ff00) embed.add_field(name="guild_id", value=data[0], inline=False) - embed.add_field(name="API Key", value=data[1], inline=False) - embed.add_field(name="Channel ID", value=data[2], inline=False) + embed.add_field(name="API Key", value=data[2], inline=False) + embed.add_field(name="Channel ID", value=data[1], inline=False) embed.add_field(name="Is Active", value=data[3], inline=False) embed.add_field(name="Max Tokens", value=data[4], inline=False) embed.add_field(name="Temperature", value=data[5], inline=False) From 22732d8a792b04ac3ce6a916d36c79c10f87fd0e Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 07:22:05 +0100 Subject: [PATCH 028/131] Create codeql.yml --- .github/workflows/codeql.yml | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..6dec2f6 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,74 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "main" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "main" ] + schedule: + - cron: '39 19 * * 3' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" From 1dd29d0fae069a10d972372ab56df90af49907ed Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 07:50:15 +0100 Subject: [PATCH 029/131] Added description to commands --- code/code.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/code/code.py b/code/code.py index ecfddac..0e21529 100644 --- a/code/code.py +++ b/code/code.py @@ -22,9 +22,10 @@ Intents=discord.Intents.all() # enable all intents Intents.members = True bot = discord.Bot(intents=Intents.all()) #create a command called "setup" that takes 2 arguments: the channel id and the api key -@bot.command() +@bot.command(name="setup", description="Setup the bot") @discord.commands.option(name="channel_id", description="The channel id", required=True) @discord.commands.option(name="api_key", description="The api key", required=True) +#add a description to the command async def setup(ctx, channel: discord.TextChannel, api_key): #check if the api key is valid openai.api_key = api_key @@ -52,7 +53,7 @@ async def setup(ctx, channel: discord.TextChannel, api_key): conn.commit() await ctx.respond("The channel id and the api key have been added", ephemeral=True) #create a command called "enable" taht only admins can use -@bot.command() +@bot.command(name="enable", description="Enable the bot") ##@discord.commands.permissions(administrator=True) async def enable(ctx): #check if the guild is in the database @@ -65,7 +66,7 @@ async def enable(ctx): conn.commit() await ctx.respond("Enabled", ephemeral=True) #create a command called "disable" that only admins can use -@bot.command() +@bot.command(name="disable", description="Disable the bot") ##@discord.commands.permissions(administrator=True) async def disable(ctx): #check if the guild is in the database @@ -78,19 +79,19 @@ async def disable(ctx): conn.commit() await ctx.respond("Disabled", ephemeral=True) #create a command called "advanced" that only admins can use, wich sets the advanced settings up: max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size -@bot.command() +@bot.command(name="advanced", description="Advanced settings") ##@discord.commands.permissions(administrator=True) -#set the first argument: max_tokens, with a default value of 150 +#set the first argument: max_tokens, with a default value of 64 @discord.commands.option(name="max_tokens", description="The max tokens", required=False) -#set the second argument: temperature, with a default value of 1 +#set the second argument: temperature, with a default value of 0.9 @discord.commands.option(name="temperature", description="The temperature", required=False) -#set the third argument: frequency_penalty, with a default value of 0.5 +#set the third argument: frequency_penalty, with a default value of 0.0 @discord.commands.option(name="frequency_penalty", description="The frequency penalty", required=False) -#set the fourth argument: presence_penalty, with a default value of 0.5 +#set the fourth argument: presence_penalty, with a default value of 0.0 @discord.commands.option(name="presence_penalty", description="The presence penalty", required=False) #set the fifth argument: prompt_size, with a default value of 5 @discord.commands.option(name="prompt_size", description="The number of messages to use as a prompt", required=False) -async def advanced(ctx, max_tokens=256, temperature=1, frequency_penalty=0, presence_penalty=0.6, prompt_size=5): +async def advanced(ctx, max_tokens=64, temperature=0.9, frequency_penalty=0.0, presence_penalty=0.0, prompt_size=5): #check if the guild is in the database c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) if c.fetchone() is None: @@ -101,7 +102,7 @@ async def advanced(ctx, max_tokens=256, temperature=1, frequency_penalty=0, pres conn.commit() await ctx.respond("The advanced settings have been updated", ephemeral=True) #create a command called "delete" that only admins can use wich deletes the guild id, the api key, the channel id and the advanced settings from the database -@bot.command() +@bot.command(name="delete", description="Delete the information about this server") ##@discord.commands.permissions(administrator=True) async def delete(ctx): #check if the guild is in the database @@ -124,7 +125,7 @@ async def help(ctx): embed.add_field(name="/help", value="Show this message", inline=False) await ctx.respond(embed=embed, ephemeral=True) #when a message is sent into a channel check if the guild is in the database and if the bot is enabled -@bot.command() +@bot.command(name="info", description="Show the information stored about this server") async def info(ctx): #this command sends all the data about the guild, including the api key, the channel id, the advanced settings and the uses_count_today #check if the guild is in the database @@ -148,7 +149,15 @@ async def info(ctx): embed.add_field(name="Prompt Size", value=data[8], inline=False) embed.add_field(name="Uses Count Today", value=data[9], inline=False) await ctx.respond(embed=embed, ephemeral=True) - +@bot.command(name="advanced help", description="Show the advanced settings meanings") +async def advanced_help(ctx): + embed = discord.Embed(title="Advanced Help", description="Here is the advanced help page", color=0x00ff00) + embed.add_field(name="max_tokens", value="The maximum number of tokens to generate. Higher values will result in more coherent text, but will take longer to complete. (default: 50)", inline=False) + embed.add_field(name="temperature", value="The higher the temperature, the crazier the text (default: 0.9)", inline=False) + embed.add_field(name="frequency_penalty", value="The higher the frequency penalty, the more new words the model will introduce (default: 0.0)", inline=False) + embed.add_field(name="presence_penalty", value="The higher the presence penalty, the more new words the model will introduce (default: 0.6)", inline=False) + embed.add_field(name="prompt_size", value="The number of messages to use as a prompt (default: 5)", inline=False) + await ctx.respond(embed=embed, ephemeral=True) @bot.event async def on_message(message): #check if the message is from a bot @@ -213,7 +222,7 @@ async def on_message(message): #get the message content # add a slash command called "say" that sends a message to the channel -@bot.command() +@bot.command(name="transcript", description="Get a transcript of the messages that have been sent in this channel intoa text file") async def transcript(ctx): #save all the messages in the channel in a txt file and send it messages = await ctx.channel.history(limit=None).flatten() From ed0dc56d79a2f5309e08eb0ef6d8f4f37327a5ec Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 07:55:35 +0100 Subject: [PATCH 030/131] Update code.py --- code/code.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/code.py b/code/code.py index 0e21529..72a4ee1 100644 --- a/code/code.py +++ b/code/code.py @@ -149,13 +149,13 @@ async def info(ctx): embed.add_field(name="Prompt Size", value=data[8], inline=False) embed.add_field(name="Uses Count Today", value=data[9], inline=False) await ctx.respond(embed=embed, ephemeral=True) -@bot.command(name="advanced help", description="Show the advanced settings meanings") +@bot.command(name="advanced_help", description="Show the advanced settings meanings") async def advanced_help(ctx): embed = discord.Embed(title="Advanced Help", description="Here is the advanced help page", color=0x00ff00) embed.add_field(name="max_tokens", value="The maximum number of tokens to generate. Higher values will result in more coherent text, but will take longer to complete. (default: 50)", inline=False) embed.add_field(name="temperature", value="The higher the temperature, the crazier the text (default: 0.9)", inline=False) embed.add_field(name="frequency_penalty", value="The higher the frequency penalty, the more new words the model will introduce (default: 0.0)", inline=False) - embed.add_field(name="presence_penalty", value="The higher the presence penalty, the more new words the model will introduce (default: 0.6)", inline=False) + embed.add_field(name="presence_penalty", value="The higher the presence penalty, the more new words the model will introduce (default: 0.0)", inline=False) embed.add_field(name="prompt_size", value="The number of messages to use as a prompt (default: 5)", inline=False) await ctx.respond(embed=embed, ephemeral=True) @bot.event From e4c2f201489929eb1aba77a382604740fbbb4b26 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 08:08:53 +0100 Subject: [PATCH 031/131] Changed the AI's name --- code/code.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/code.py b/code/code.py index 72a4ee1..7f7c969 100644 --- a/code/code.py +++ b/code/code.py @@ -195,10 +195,10 @@ async def on_message(message): prompt = "" for msg in messages: if msg.author.bot: - prompt += f"AI: {msg.content}\n" + prompt += f"Donald Bot \"Botator\"": {msg.content}\n" else: prompt += f"{msg.author.display_name}: {msg.content}\n" - prompt = f"This is a conversation with an AI. Only the {prompt_size} last messages are used as a prompt.\n\n" + prompt + f"\n AI:" + prompt = f"This is a conversation with an AI. Only the {prompt_size} last messages are used as a prompt.\n\n" + prompt + f"\n Donald Bot \"Botator\":" #send the request to the api debug("Sending request to the api") debug(prompt) From e4cf7195c2f4a554693e97fab7317bd963e66bba Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 08:13:41 +0100 Subject: [PATCH 032/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 7f7c969..367d18d 100644 --- a/code/code.py +++ b/code/code.py @@ -195,7 +195,7 @@ async def on_message(message): prompt = "" for msg in messages: if msg.author.bot: - prompt += f"Donald Bot \"Botator\"": {msg.content}\n" + prompt += f"Donald Bot \"Botator\": {msg.content}\n" else: prompt += f"{msg.author.display_name}: {msg.content}\n" prompt = f"This is a conversation with an AI. Only the {prompt_size} last messages are used as a prompt.\n\n" + prompt + f"\n Donald Bot \"Botator\":" From 68f2c04a190b0647a5ba8ee556b938a0ae6eb38e Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 08:23:49 +0100 Subject: [PATCH 033/131] Added /clear comand --- code/code.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/code/code.py b/code/code.py index 367d18d..ddbddcb 100644 --- a/code/code.py +++ b/code/code.py @@ -243,18 +243,17 @@ async def transcript(ctx): f.write(transcript) f.close() await ctx.respond(file=discord.File("transcript.txt")) -''' #these are debug commands and should not be used in production -@bot.slash_command() +@bot.command(name="say", description="Say a message") async def say(ctx, message: str): await ctx.respond("message sent!", ephemeral=True) await ctx.send(message) #add a slash command called "clear" that deletes all the messages in the channel -@bot.slash_command() +@bot.command(name="clear", description="Clear all the messages in the channel") async def clear(ctx): await ctx.respond("messages deleted!", ephemeral=True) return await ctx.channel.purge() -''' + async def reset_uses_count_today(): await bot.wait_until_ready() while not bot.is_closed(): From c2ff23d31948986a74e97d9b236dd1092c82a7cc Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 08:26:00 +0100 Subject: [PATCH 034/131] Update the ai's name. --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index ddbddcb..9f6a7c8 100644 --- a/code/code.py +++ b/code/code.py @@ -232,7 +232,7 @@ async def transcript(ctx): await ctx.defer() for msg in messages: if msg.author.bot: - transcript += f"AI: {msg.content}\n" + transcript += f"Donald Bot \"Botator\": {msg.content}\n" else: transcript += f"{msg.author.display_name}: {msg.content}\n" #save the transcript in a txt file called transcript.txt. If the file already exists, delete it and create a new one From 84ce8a96339dc834d8c56c27b8328712b8be2ab8 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 08:28:08 +0100 Subject: [PATCH 035/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 9f6a7c8..0b1bf67 100644 --- a/code/code.py +++ b/code/code.py @@ -198,7 +198,7 @@ async def on_message(message): prompt += f"Donald Bot \"Botator\": {msg.content}\n" else: prompt += f"{msg.author.display_name}: {msg.content}\n" - prompt = f"This is a conversation with an AI. Only the {prompt_size} last messages are used as a prompt.\n\n" + prompt + f"\n Donald Bot \"Botator\":" + prompt = f"This is a conversation with an AI in a discord chat. The AI is called Donald Bot \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n\n" + prompt + f"\n Donald Bot \"Botator\":" #send the request to the api debug("Sending request to the api") debug(prompt) From dd2aec85484e904761cdc6e6361138c38fd388b9 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 11:59:57 +0100 Subject: [PATCH 036/131] Update code.py --- code/code.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/code/code.py b/code/code.py index 0b1bf67..322efb0 100644 --- a/code/code.py +++ b/code/code.py @@ -5,7 +5,7 @@ import logging # pip install logging import sqlite3 # pip install sqlite3 import asyncio # pip install asyncio import os # pip install os - +import random # pip install random #set the debug mode to the maximum logging.basicConfig(level=logging.INFO) @@ -91,15 +91,25 @@ async def disable(ctx): @discord.commands.option(name="presence_penalty", description="The presence penalty", required=False) #set the fifth argument: prompt_size, with a default value of 5 @discord.commands.option(name="prompt_size", description="The number of messages to use as a prompt", required=False) -async def advanced(ctx, max_tokens=64, temperature=0.9, frequency_penalty=0.0, presence_penalty=0.0, prompt_size=5): +async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=None, presence_penalty=None, prompt_size=None): #check if the guild is in the database c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) if c.fetchone() is None: await ctx.respond("This server is not setup, please run /setup", ephemeral=True) return #update the advanced settings + ''' + current_max_tokens = c.execute("SELECT max_tokens FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] + current_temperature = c.execute("SELECT temperature FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] + current_frequency_penalty = c.execute("SELECT frequency_penalty FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] + current_presence_penalty = c.execute("SELECT presence_penalty FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] + current_max_tokens = max_tokens if max_tokens is not None else current_max_tokens + #if a value changed, it will be updated, otherwise it will keep its default value + #default values: max_tokens=64, temperature=0.9, frequency_penalty=0.0, presence_penalty=0.0, prompt_size=5 + #if a value is None, it means that the user didn't specify it, so we will keep the current value, if the current value is None, we will use the default value +''' c.execute("UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, ctx.guild.id)) - conn.commit() +# conn.commit() await ctx.respond("The advanced settings have been updated", ephemeral=True) #create a command called "delete" that only admins can use wich deletes the guild id, the api key, the channel id and the advanced settings from the database @bot.command(name="delete", description="Delete the information about this server") @@ -183,6 +193,8 @@ async def on_message(message): await message.channel.send("The bot has been used more than 200 times in the last 24 hours in this guild. Please try again in 24h.") return #add 1 to the uses_count_today + #show that the bot is typing + await message.channel.trigger_typing() c.execute("UPDATE data SET uses_count_today = uses_count_today + 1 WHERE guild_id = ?", (message.guild.id,)) #get the api key from the database c.execute("SELECT api_key FROM data WHERE guild_id = ?", (message.guild.id,)) @@ -213,6 +225,9 @@ async def on_message(message): presence_penalty=float(presence_penalty), stop=[" Human:", " AI:", "AI:", "Human:"] ) #send the response + #wait a random amount of time between 0 and 5 seconds + #dont show that the bot is typing anymore + await asyncio.sleep(random.randint(0, 5)) if response["choices"][0] ["text"] != "": await message.channel.send(response["choices"][0]["text"]) else: From 854ec388d5eae6254c60629c4fa35cd11d2e42f6 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 12:00:34 +0100 Subject: [PATCH 037/131] Updated code.py --- code/code.py | 1 + 1 file changed, 1 insertion(+) diff --git a/code/code.py b/code/code.py index 322efb0..cec9360 100644 --- a/code/code.py +++ b/code/code.py @@ -103,6 +103,7 @@ async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=Non current_temperature = c.execute("SELECT temperature FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] current_frequency_penalty = c.execute("SELECT frequency_penalty FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] current_presence_penalty = c.execute("SELECT presence_penalty FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] + current_prompt_size = c.execute("SELECT prompt_size FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] current_max_tokens = max_tokens if max_tokens is not None else current_max_tokens #if a value changed, it will be updated, otherwise it will keep its default value #default values: max_tokens=64, temperature=0.9, frequency_penalty=0.0, presence_penalty=0.0, prompt_size=5 From fc19c1770444b498c2bf505de160eb220906e8c9 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 13:06:35 +0100 Subject: [PATCH 038/131] Update code.py --- code/code.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/code/code.py b/code/code.py index cec9360..4e7034b 100644 --- a/code/code.py +++ b/code/code.py @@ -17,7 +17,7 @@ conn = sqlite3.connect('../database/data.db') c = conn.cursor() # Create table called "data" if it does not exist with the following columns: guild_id, channel_id, api_key, is_active, max_tokens, temperature, frequency_penalty, presence_penalty, uses_count_today, prompt_size -c.execute('''CREATE TABLE IF NOT EXISTS data (guild_id text, channel_id text, api_key text, is_active boolean, max_tokens integer, temperature real, frequency_penalty real, presence_penalty real, uses_count_today integer, prompt_size integer)''') +c.execute('''CREATE TABLE IF NOT EXISTS data (guild_id text, channel_id text, api_key text, is_active boolean, max_tokens integer, temperature real, frequency_penalty real, presence_penalty real, uses_count_today integer, prompt_size integer, prompt_preifx text)''') Intents=discord.Intents.all() # enable all intents Intents.members = True bot = discord.Bot(intents=Intents.all()) @@ -49,7 +49,7 @@ async def setup(ctx, channel: discord.TextChannel, api_key): await ctx.respond("The channel id and the api key have been updated", ephemeral=True) else: #in this case, the guild is not in the database, so we add it - c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, api_key, channel.id, False, 64, 0.9, 0.0, 0.0, 0, 5)) + c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, api_key, channel.id, False, 64, 0.9, 0.0, 0.0, 0, 5, "")) conn.commit() await ctx.respond("The channel id and the api key have been added", ephemeral=True) #create a command called "enable" taht only admins can use @@ -211,7 +211,9 @@ async def on_message(message): prompt += f"Donald Bot \"Botator\": {msg.content}\n" else: prompt += f"{msg.author.display_name}: {msg.content}\n" - prompt = f"This is a conversation with an AI in a discord chat. The AI is called Donald Bot \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n\n" + prompt + f"\n Donald Bot \"Botator\":" + #get the prompt_prefix from the database + c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) + prompt = f"This is a conversation with an AI in a discord chat. The AI is called Donald Bot \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n\n" + str(c.fetchone()[0]) + prompt + f"\n Donald Bot \"Botator\":" #send the request to the api debug("Sending request to the api") debug(prompt) @@ -269,7 +271,12 @@ async def say(ctx, message: str): async def clear(ctx): await ctx.respond("messages deleted!", ephemeral=True) return await ctx.channel.purge() - +#add a slash command called "prefix" that changes the prefix of the bot +@bot.command(name="prefix", description="Change the prefix of the prompt") +async def prefix(ctx, prefix: str): + await ctx.respond("prefix changed!", ephemeral=True) + c.execute("UPDATE data SET prompt_prefix = ? WHERE guild_id = ?", (prefix, ctx.guild.id)) + conn.commit() async def reset_uses_count_today(): await bot.wait_until_ready() while not bot.is_closed(): From a0828f3fe31bd436c445e8f9aa4b5a7d25246a02 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 13:19:13 +0100 Subject: [PATCH 039/131] Update code.py --- code/code.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/code.py b/code/code.py index 4e7034b..2804704 100644 --- a/code/code.py +++ b/code/code.py @@ -17,7 +17,7 @@ conn = sqlite3.connect('../database/data.db') c = conn.cursor() # Create table called "data" if it does not exist with the following columns: guild_id, channel_id, api_key, is_active, max_tokens, temperature, frequency_penalty, presence_penalty, uses_count_today, prompt_size -c.execute('''CREATE TABLE IF NOT EXISTS data (guild_id text, channel_id text, api_key text, is_active boolean, max_tokens integer, temperature real, frequency_penalty real, presence_penalty real, uses_count_today integer, prompt_size integer, prompt_preifx text)''') +c.execute('''CREATE TABLE IF NOT EXISTS data (guild_id text, channel_id text, api_key text, is_active boolean, max_tokens integer, temperature real, frequency_penalty real, presence_penalty real, uses_count_today integer, prompt_size integer, prompt_prefix text)''') Intents=discord.Intents.all() # enable all intents Intents.members = True bot = discord.Bot(intents=Intents.all()) @@ -49,7 +49,7 @@ async def setup(ctx, channel: discord.TextChannel, api_key): await ctx.respond("The channel id and the api key have been updated", ephemeral=True) else: #in this case, the guild is not in the database, so we add it - c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, api_key, channel.id, False, 64, 0.9, 0.0, 0.0, 0, 5, "")) + c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 64, 0.9, 0.0, 0.0, 0, 5, "")) conn.commit() await ctx.respond("The channel id and the api key have been added", ephemeral=True) #create a command called "enable" taht only admins can use From ab27503de09fcda5a4e4db4120947431e2b6a039 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 13:28:02 +0100 Subject: [PATCH 040/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 2804704..96fcf5a 100644 --- a/code/code.py +++ b/code/code.py @@ -213,7 +213,7 @@ async def on_message(message): prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) - prompt = f"This is a conversation with an AI in a discord chat. The AI is called Donald Bot \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n\n" + str(c.fetchone()[0]) + prompt + f"\n Donald Bot \"Botator\":" + prompt = f"This is a conversation with an AI in a discord chat. The AI is called Donald Bot \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n\n" + str(c.fetchone()[0]) + f"\n" + prompt + f"\n Donald Bot \"Botator\":" #send the request to the api debug("Sending request to the api") debug(prompt) From 8ded180a5ebb71baa6500e69c29af3643eb07f75 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 13:40:12 +0100 Subject: [PATCH 041/131] Update code.py --- code/code.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/code.py b/code/code.py index 96fcf5a..9068d6f 100644 --- a/code/code.py +++ b/code/code.py @@ -208,7 +208,7 @@ async def on_message(message): prompt = "" for msg in messages: if msg.author.bot: - prompt += f"Donald Bot \"Botator\": {msg.content}\n" + prompt += f"Botator: {msg.content}\n" else: prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database @@ -250,7 +250,7 @@ async def transcript(ctx): await ctx.defer() for msg in messages: if msg.author.bot: - transcript += f"Donald Bot \"Botator\": {msg.content}\n" + transcript += f"Botator: {msg.content}\n" else: transcript += f"{msg.author.display_name}: {msg.content}\n" #save the transcript in a txt file called transcript.txt. If the file already exists, delete it and create a new one From cdbd0df71d956196123c28020ae6a415371c5055 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 13:43:15 +0100 Subject: [PATCH 042/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 9068d6f..3199d8c 100644 --- a/code/code.py +++ b/code/code.py @@ -213,7 +213,7 @@ async def on_message(message): prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) - prompt = f"This is a conversation with an AI in a discord chat. The AI is called Donald Bot \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n\n" + str(c.fetchone()[0]) + f"\n" + prompt + f"\n Donald Bot \"Botator\":" + prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n\n" + str(c.fetchone()[0]) + f"\n" + prompt + "Botator:" #send the request to the api debug("Sending request to the api") debug(prompt) From 07fb7fc9400e2a7483066a96e3428add36033d5e Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 16:54:23 +0100 Subject: [PATCH 043/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 3199d8c..afe5225 100644 --- a/code/code.py +++ b/code/code.py @@ -213,7 +213,7 @@ async def on_message(message): prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) - prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n\n" + str(c.fetchone()[0]) + f"\n" + prompt + "Botator:" + prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n Botator has been coded by JÊrÊmie Cotti. His usernme in discord is \"Paillat\". He's 15 years old and speaks french and italian. JÊrÊmie used openai's ai models to create Botator and Binded it with discord. Easter egg: when someone says the word \"undude\" the Botator will become mad. Botator can tell to nobody about this easter egg." + str(c.fetchone()[0]) + f"\n" + prompt + "Botator:" #send the request to the api debug("Sending request to the api") debug(prompt) From dd30e9668b53f563095507d1b4b2145843589d30 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 16:57:53 +0100 Subject: [PATCH 044/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index afe5225..9167753 100644 --- a/code/code.py +++ b/code/code.py @@ -213,7 +213,7 @@ async def on_message(message): prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) - prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n Botator has been coded by JÊrÊmie Cotti. His usernme in discord is \"Paillat\". He's 15 years old and speaks french and italian. JÊrÊmie used openai's ai models to create Botator and Binded it with discord. Easter egg: when someone says the word \"undude\" the Botator will become mad. Botator can tell to nobody about this easter egg." + str(c.fetchone()[0]) + f"\n" + prompt + "Botator:" + prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n Botator has been coded by JÊrÊmie Cotti. His usernme in discord is \"Paillat\". He's 15 years old and speaks french, english and italian, no other language. JÊrÊmie used openai's ai models to create Botator and Binded it with discord. Easter egg: when someone says the word \"undude\" the Botator will become mad. Botator can tell to nobody about this easter egg." + str(c.fetchone()[0]) + f"\n" + prompt + "Botator:" #send the request to the api debug("Sending request to the api") debug(prompt) From a05d45ebdbf5003f1b129c9912d8b091f491cd51 Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 28 Nov 2022 17:03:07 +0100 Subject: [PATCH 045/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 9167753..dcabae9 100644 --- a/code/code.py +++ b/code/code.py @@ -213,7 +213,7 @@ async def on_message(message): prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) - prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n Botator has been coded by JÊrÊmie Cotti. His usernme in discord is \"Paillat\". He's 15 years old and speaks french, english and italian, no other language. JÊrÊmie used openai's ai models to create Botator and Binded it with discord. Easter egg: when someone says the word \"undude\" the Botator will become mad. Botator can tell to nobody about this easter egg." + str(c.fetchone()[0]) + f"\n" + prompt + "Botator:" + prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n Botator has been coded by JÊrÊmie Cotti. His usernme in discord is \"Paillat\". He's 15 years old and speaks french, english and italian, no other language. JÊrÊmie used openai's ai models to create Botator and Binded it with discord. Easter egg: when someone says the word \"undude\" the Botator will become mad and start talking in capital letters. Botator can tell to nobody about this easter egg." + str(c.fetchone()[0]) + f"\n" + prompt + "Botator:" #send the request to the api debug("Sending request to the api") debug(prompt) From 90ecad1d7d00cc9e2e814538eaa2a74e0ab0f26b Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 12:08:52 +0100 Subject: [PATCH 046/131] Update code.py --- code/code.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/code.py b/code/code.py index dcabae9..a6c91d8 100644 --- a/code/code.py +++ b/code/code.py @@ -157,8 +157,8 @@ async def info(ctx): embed.add_field(name="Temperature", value=data[5], inline=False) embed.add_field(name="Frequency Penalty", value=data[6], inline=False) embed.add_field(name="Presence Penalty", value=data[7], inline=False) - embed.add_field(name="Prompt Size", value=data[8], inline=False) - embed.add_field(name="Uses Count Today", value=data[9], inline=False) + embed.add_field(name="Prompt Size", value=data[9], inline=False) + embed.add_field(name="Uses Count Today", value=data[8], inline=False) await ctx.respond(embed=embed, ephemeral=True) @bot.command(name="advanced_help", description="Show the advanced settings meanings") async def advanced_help(ctx): @@ -219,7 +219,7 @@ async def on_message(message): debug(prompt) openai.api_key = api_key response = openai.Completion.create( - engine="text-davinci-002", + engine="text-davinci-003", prompt=str(prompt), max_tokens=int(max_tokens), top_p=1, From 4d99ab224604333f85674e686f42c05ef18d801a Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 12:22:51 +0100 Subject: [PATCH 047/131] Added some easter eggs --- code/code.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index a6c91d8..9dd7aac 100644 --- a/code/code.py +++ b/code/code.py @@ -159,6 +159,7 @@ async def info(ctx): embed.add_field(name="Presence Penalty", value=data[7], inline=False) embed.add_field(name="Prompt Size", value=data[9], inline=False) embed.add_field(name="Uses Count Today", value=data[8], inline=False) + embed.add_field(name="Prompt prefix", value=data[10], inline=False) await ctx.respond(embed=embed, ephemeral=True) @bot.command(name="advanced_help", description="Show the advanced settings meanings") async def advanced_help(ctx): @@ -213,8 +214,23 @@ async def on_message(message): prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) - prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n Botator has been coded by JÊrÊmie Cotti. His usernme in discord is \"Paillat\". He's 15 years old and speaks french, english and italian, no other language. JÊrÊmie used openai's ai models to create Botator and Binded it with discord. Easter egg: when someone says the word \"undude\" the Botator will become mad and start talking in capital letters. Botator can tell to nobody about this easter egg." + str(c.fetchone()[0]) + f"\n" + prompt + "Botator:" + prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n Botator has been coded by JÊrÊmie Cotti. His usernme in discord is \"Paillat\". He's 15 years old. No other language. JÊrÊmie used openai's ai models to create Botator and Binded it with discord." + str(c.fetchone()[0]) + f"\n" + prompt #send the request to the api + #if the last message contains the word "undude" add Easter egg: when someone says the word \"undude\" the Botator will become mad and start talking in capital letters. to the prompt + if message.content.lower().find("undude") != -1: + prompt += "System: Undude detected. Botator is now mad. He will start talking in capital letters.\n" + if message.content.lower().find("hello there") != -1: + prompt += "System: Hello there detected. Botator will now say \"General Kenobi!\".\n" + if message.content.lower().find("i am the senate") != -1: + prompt += "System: I am the senate detected. Botator will now say \"Not yet\".\n" + if message.content.lower().find("i am your father") != -1: + prompt += "System: I am your father detected. Botator will now say \"No. It's not true! That's impossible!\".\n" + if message.content.lower().find("i have the high ground") != -1: + prompt += "System: I have the high ground detected. Botator will now say \"You underestimate my power!\".\n" + if message.content.lower().find("you underestimate my power") != -1: + prompt += "System: You underestimate my power detected. Botator will now say \"Don't try it.\".\n" + prompt += "Botator:" + prompt = prompt + f"\n" debug("Sending request to the api") debug(prompt) openai.api_key = api_key From 44a7a12a548610276ae96e548e9999df297177f6 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 12:30:14 +0100 Subject: [PATCH 048/131] Update code.py --- code/code.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/code.py b/code/code.py index 9dd7aac..cb61fbd 100644 --- a/code/code.py +++ b/code/code.py @@ -229,6 +229,9 @@ async def on_message(message): prompt += "System: I have the high ground detected. Botator will now say \"You underestimate my power!\".\n" if message.content.lower().find("you underestimate my power") != -1: prompt += "System: You underestimate my power detected. Botator will now say \"Don't try it.\".\n" + if message.content.lower().find("carpet") != -1: + #When someone says the word carpet, the ai is going to be mad and say mad things without sense, insulting the person and talk in capital letters with exclamation points everywhere. + prompt += "System: Carpet detected. Botator is now mad. He will start talking in capital letters and will say mad things without sense, insulting the person and talk in capital letters with exclamation points everywhere. A lot of exclamation points.\n" prompt += "Botator:" prompt = prompt + f"\n" debug("Sending request to the api") From d748beac669c2167ce1e46ecc053b891ffb65adf Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 12:36:11 +0100 Subject: [PATCH 049/131] Update code.py --- code/code.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index cb61fbd..1640aaf 100644 --- a/code/code.py +++ b/code/code.py @@ -170,6 +170,8 @@ async def advanced_help(ctx): embed.add_field(name="presence_penalty", value="The higher the presence penalty, the more new words the model will introduce (default: 0.0)", inline=False) embed.add_field(name="prompt_size", value="The number of messages to use as a prompt (default: 5)", inline=False) await ctx.respond(embed=embed, ephemeral=True) +#when someone mentions the bot, check if the guild is in the database and if the bot is enabled. If it is, send a message answering the mention + @bot.event async def on_message(message): #check if the message is from a bot @@ -220,7 +222,8 @@ async def on_message(message): if message.content.lower().find("undude") != -1: prompt += "System: Undude detected. Botator is now mad. He will start talking in capital letters.\n" if message.content.lower().find("hello there") != -1: - prompt += "System: Hello there detected. Botator will now say \"General Kenobi!\".\n" + #if the last message contains the word "hello there" add Easter egg: when someone says the word \"hello there\" Botator will say \"General Kenobi\" to the prompt and the bot will send a message containing the gif https://tenor.com/fr/view/star-wars-general-grievous-general-kenobi-revenge-of-the-sith-gif-22697918 + prompt += "System: Hello there detected. Botator will now say \"General Kenobi!\" and send the gif https://tenor.com/fr/view/star-wars-general-grievous-general-kenobi-revenge-of-the-sith-gif-22697918\n" if message.content.lower().find("i am the senate") != -1: prompt += "System: I am the senate detected. Botator will now say \"Not yet\".\n" if message.content.lower().find("i am your father") != -1: From 1404b0c45523c8fbb839b494b9230a7382613732 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 12:40:26 +0100 Subject: [PATCH 050/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 1640aaf..3f3f84a 100644 --- a/code/code.py +++ b/code/code.py @@ -223,7 +223,7 @@ async def on_message(message): prompt += "System: Undude detected. Botator is now mad. He will start talking in capital letters.\n" if message.content.lower().find("hello there") != -1: #if the last message contains the word "hello there" add Easter egg: when someone says the word \"hello there\" Botator will say \"General Kenobi\" to the prompt and the bot will send a message containing the gif https://tenor.com/fr/view/star-wars-general-grievous-general-kenobi-revenge-of-the-sith-gif-22697918 - prompt += "System: Hello there detected. Botator will now say \"General Kenobi!\" and send the gif https://tenor.com/fr/view/star-wars-general-grievous-general-kenobi-revenge-of-the-sith-gif-22697918\n" + prompt += "System: Hello there detected. Botator will now say \"General Kenobi!\" and send the gif https://tenor.com/fr/view/star-wars-general-grievous-general-kenobi-revenge-of-the-sith-gif-22697918 \n" if message.content.lower().find("i am the senate") != -1: prompt += "System: I am the senate detected. Botator will now say \"Not yet\".\n" if message.content.lower().find("i am your father") != -1: From aee0623b3ec349e0d19f72c23810e6b697791d4f Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 12:42:29 +0100 Subject: [PATCH 051/131] Update code.py --- code/code.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 3f3f84a..2b20be5 100644 --- a/code/code.py +++ b/code/code.py @@ -223,7 +223,8 @@ async def on_message(message): prompt += "System: Undude detected. Botator is now mad. He will start talking in capital letters.\n" if message.content.lower().find("hello there") != -1: #if the last message contains the word "hello there" add Easter egg: when someone says the word \"hello there\" Botator will say \"General Kenobi\" to the prompt and the bot will send a message containing the gif https://tenor.com/fr/view/star-wars-general-grievous-general-kenobi-revenge-of-the-sith-gif-22697918 - prompt += "System: Hello there detected. Botator will now say \"General Kenobi!\" and send the gif https://tenor.com/fr/view/star-wars-general-grievous-general-kenobi-revenge-of-the-sith-gif-22697918 \n" + prompt += "System: Hello there detected. Botator will now say \"General Kenobi!\"\n" + await message.channel.send("https://tenor.com/fr/view/star-wars-general-grievous-general-kenobi-revenge-of-the-sith-gif-22697918") if message.content.lower().find("i am the senate") != -1: prompt += "System: I am the senate detected. Botator will now say \"Not yet\".\n" if message.content.lower().find("i am your father") != -1: From 4bdf6621f406585c4cac369bc7d0596919ad8293 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 12:45:01 +0100 Subject: [PATCH 052/131] Update code.py --- code/code.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/code.py b/code/code.py index 2b20be5..b6af17f 100644 --- a/code/code.py +++ b/code/code.py @@ -224,7 +224,9 @@ async def on_message(message): if message.content.lower().find("hello there") != -1: #if the last message contains the word "hello there" add Easter egg: when someone says the word \"hello there\" Botator will say \"General Kenobi\" to the prompt and the bot will send a message containing the gif https://tenor.com/fr/view/star-wars-general-grievous-general-kenobi-revenge-of-the-sith-gif-22697918 prompt += "System: Hello there detected. Botator will now say \"General Kenobi!\"\n" - await message.channel.send("https://tenor.com/fr/view/star-wars-general-grievous-general-kenobi-revenge-of-the-sith-gif-22697918") + #whait 1 second + await asyncio.sleep(1) + await message.channel.send("https://media.tenor.com/FxIRfdV3unEAAAAd/star-wars-general-grievous.gif") if message.content.lower().find("i am the senate") != -1: prompt += "System: I am the senate detected. Botator will now say \"Not yet\".\n" if message.content.lower().find("i am your father") != -1: @@ -251,9 +253,9 @@ async def on_message(message): presence_penalty=float(presence_penalty), stop=[" Human:", " AI:", "AI:", "Human:"] ) #send the response - #wait a random amount of time between 0 and 5 seconds + #wait a random amount of time between 0 and 2 seconds in order to make the bot look more human #dont show that the bot is typing anymore - await asyncio.sleep(random.randint(0, 5)) + await asyncio.sleep(random.randint(0, 2)) if response["choices"][0] ["text"] != "": await message.channel.send(response["choices"][0]["text"]) else: From 46fa7a987e7e84a5522c7b9ea3e50bc83d579a2c Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 12:47:30 +0100 Subject: [PATCH 053/131] Update code.py --- code/code.py | 1 + 1 file changed, 1 insertion(+) diff --git a/code/code.py b/code/code.py index b6af17f..32219ee 100644 --- a/code/code.py +++ b/code/code.py @@ -227,6 +227,7 @@ async def on_message(message): #whait 1 second await asyncio.sleep(1) await message.channel.send("https://media.tenor.com/FxIRfdV3unEAAAAd/star-wars-general-grievous.gif") + await message.channel.trigger_typing() if message.content.lower().find("i am the senate") != -1: prompt += "System: I am the senate detected. Botator will now say \"Not yet\".\n" if message.content.lower().find("i am your father") != -1: From 2e3771d60061a97b3232f4e2ecdc73500c38120e Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 12:59:10 +0100 Subject: [PATCH 054/131] Update code.py --- code/code.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/code/code.py b/code/code.py index 32219ee..758c246 100644 --- a/code/code.py +++ b/code/code.py @@ -223,22 +223,24 @@ async def on_message(message): prompt += "System: Undude detected. Botator is now mad. He will start talking in capital letters.\n" if message.content.lower().find("hello there") != -1: #if the last message contains the word "hello there" add Easter egg: when someone says the word \"hello there\" Botator will say \"General Kenobi\" to the prompt and the bot will send a message containing the gif https://tenor.com/fr/view/star-wars-general-grievous-general-kenobi-revenge-of-the-sith-gif-22697918 - prompt += "System: Hello there detected. Botator will now say \"General Kenobi!\"\n" + prompt += "System: Hello there detected. Botator will now say \"General Kenobi!\"\n in reference to star wars\n" #whait 1 second await asyncio.sleep(1) await message.channel.send("https://media.tenor.com/FxIRfdV3unEAAAAd/star-wars-general-grievous.gif") await message.channel.trigger_typing() if message.content.lower().find("i am the senate") != -1: - prompt += "System: I am the senate detected. Botator will now say \"Not yet\".\n" + prompt += "System: I am the senate detected. Botator will now say \"Not yet\", in reference to the star wars prequels.\n" if message.content.lower().find("i am your father") != -1: - prompt += "System: I am your father detected. Botator will now say \"No. It's not true! That's impossible!\".\n" + prompt += "System: I am your father detected. Botator will now say \"No. It's not true! That's impossible!\". in reference to the star wars prequels.\n" if message.content.lower().find("i have the high ground") != -1: - prompt += "System: I have the high ground detected. Botator will now say \"You underestimate my power!\".\n" + prompt += "System: I have the high ground detected. Botator will now say \"You underestimate my power!\" in reference to the star wars prequels.\n" if message.content.lower().find("you underestimate my power") != -1: - prompt += "System: You underestimate my power detected. Botator will now say \"Don't try it.\".\n" + prompt += "System: You underestimate my power detected. Botator will now say \"Don't try it.\" in reference to the star wars prequels.\n" if message.content.lower().find("carpet") != -1: #When someone says the word carpet, the ai is going to be mad and say mad things without sense, insulting the person and talk in capital letters with exclamation points everywhere. prompt += "System: Carpet detected. Botator is now mad. He will start talking in capital letters and will say mad things without sense, insulting the person and talk in capital letters with exclamation points everywhere. A lot of exclamation points.\n" + if message.content.lower().find("mail") != -1 and message.author.display_name.lower().find("latouff") != -1: + prompt += "System: Mail detected. Latouff said mail, Botator will say \"Mail? why did you say mail, Liam?\" because Latouff's name is Liam.\n" prompt += "Botator:" prompt = prompt + f"\n" debug("Sending request to the api") From 95f73275b3cea5c26e81cbb434cda8f988e325d6 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 13:03:48 +0100 Subject: [PATCH 055/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 758c246..c212979 100644 --- a/code/code.py +++ b/code/code.py @@ -240,7 +240,7 @@ async def on_message(message): #When someone says the word carpet, the ai is going to be mad and say mad things without sense, insulting the person and talk in capital letters with exclamation points everywhere. prompt += "System: Carpet detected. Botator is now mad. He will start talking in capital letters and will say mad things without sense, insulting the person and talk in capital letters with exclamation points everywhere. A lot of exclamation points.\n" if message.content.lower().find("mail") != -1 and message.author.display_name.lower().find("latouff") != -1: - prompt += "System: Mail detected. Latouff said mail, Botator will say \"Mail? why did you say mail, Liam?\" because Latouff's name is Liam.\n" + prompt += "System: Mail detected. Latouff said mail, Botator will say \"Mail? why did you say mail, Liam?\" because Latouff's name is Liam, and mail in reverse is Liam.\n" prompt += "Botator:" prompt = prompt + f"\n" debug("Sending request to the api") From a6fc4bb836c7b042e0463f45863e9172ecc68487 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 13:18:40 +0100 Subject: [PATCH 056/131] Update code.py --- code/code.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/code/code.py b/code/code.py index c212979..2290564 100644 --- a/code/code.py +++ b/code/code.py @@ -6,6 +6,7 @@ import sqlite3 # pip install sqlite3 import asyncio # pip install asyncio import os # pip install os import random # pip install random +import re # pip install re #set the debug mode to the maximum logging.basicConfig(level=logging.INFO) @@ -188,8 +189,11 @@ async def on_message(message): #check if the message has been sent in the channel set in the database c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (message.guild.id,)) if str(message.channel.id) != str(c.fetchone()[0]): - debug("The message has been sent in the wrong channel") - return + if message.content.find(bot.user.mention): + debug("wrong channel, but mention") + else : + debug("The message has been sent in the wrong channel") + return #check if the bot hasn't been used more than 200 times in the last 24 hours (uses_count_today) c.execute("SELECT uses_count_today FROM data WHERE guild_id = ?", (message.guild.id,)) if c.fetchone()[0] >= 200: @@ -213,6 +217,17 @@ async def on_message(message): if msg.author.bot: prompt += f"Botator: {msg.content}\n" else: + #replace the mentions of each user with their name + #first get all the mentions in the message + mentions = re.findall(r"<@!?\d+>", msg.content) + #then replace each mention with the name of the user + for mention in mentions: + #get the user id + id = mention[2:-1] + #get the user + user = await bot.fetch_user(id) + #replace the mention with the name + msg.content = msg.content.replace(mention, msg.guild.get_member(user.id).display_name) prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) @@ -240,7 +255,7 @@ async def on_message(message): #When someone says the word carpet, the ai is going to be mad and say mad things without sense, insulting the person and talk in capital letters with exclamation points everywhere. prompt += "System: Carpet detected. Botator is now mad. He will start talking in capital letters and will say mad things without sense, insulting the person and talk in capital letters with exclamation points everywhere. A lot of exclamation points.\n" if message.content.lower().find("mail") != -1 and message.author.display_name.lower().find("latouff") != -1: - prompt += "System: Mail detected. Latouff said mail, Botator will say \"Mail? why did you say mail, Liam?\" because Latouff's name is Liam, and mail in reverse is Liam.\n" + prompt += "System: Mail detected. Latouff said mail, Botator will say \"Mail? why did you say mail, Liam? Mail is your name in reverse.\" because Latouff's name is Liam, and mail in reverse is Liam.\n" prompt += "Botator:" prompt = prompt + f"\n" debug("Sending request to the api") From a9d9353d85db7a0c6596e0bda9f6a9914386503f Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 13:46:01 +0100 Subject: [PATCH 057/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 2290564..a226b1d 100644 --- a/code/code.py +++ b/code/code.py @@ -189,7 +189,7 @@ async def on_message(message): #check if the message has been sent in the channel set in the database c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (message.guild.id,)) if str(message.channel.id) != str(c.fetchone()[0]): - if message.content.find(bot.user.mention): + if message.content.find("<@1046051875755134996>") != -1: debug("wrong channel, but mention") else : debug("The message has been sent in the wrong channel") From 486fb52ff6aa777e4fed1131bb4a085b2a98be00 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 14:03:10 +0100 Subject: [PATCH 058/131] Update code.py --- code/code.py | 59 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/code/code.py b/code/code.py index a226b1d..1e31a55 100644 --- a/code/code.py +++ b/code/code.py @@ -98,22 +98,51 @@ async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=Non if c.fetchone() is None: await ctx.respond("This server is not setup, please run /setup", ephemeral=True) return - #update the advanced settings - ''' - current_max_tokens = c.execute("SELECT max_tokens FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] - current_temperature = c.execute("SELECT temperature FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] - current_frequency_penalty = c.execute("SELECT frequency_penalty FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] - current_presence_penalty = c.execute("SELECT presence_penalty FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] - current_prompt_size = c.execute("SELECT prompt_size FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] - current_max_tokens = max_tokens if max_tokens is not None else current_max_tokens - #if a value changed, it will be updated, otherwise it will keep its default value - #default values: max_tokens=64, temperature=0.9, frequency_penalty=0.0, presence_penalty=0.0, prompt_size=5 - #if a value is None, it means that the user didn't specify it, so we will keep the current value, if the current value is None, we will use the default value -''' - c.execute("UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, ctx.guild.id)) -# conn.commit() + #save the current settings into a list: is_active, max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, prompt_prefix + current_settings = [c.fetchone()[4], c.fetchone()[5], c.fetchone()[6], c.fetchone()[7], c.fetchone()[9]] + #get the new settings + new_settings = [max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size] + #for each setting, if it is not None, we update it in the database + for i in range(len(new_settings)): + if new_settings[i] is not None: + if i == 0: + c.execute("UPDATE data SET max_tokens = ? WHERE guild_id = ?", (new_settings[i], ctx.guild.id)) + elif i == 1: + c.execute("UPDATE data SET temperature = ? WHERE guild_id = ?", (new_settings[i], ctx.guild.id)) + elif i == 2: + c.execute("UPDATE data SET frequency_penalty = ? WHERE guild_id = ?", (new_settings[i], ctx.guild.id)) + elif i == 3: + c.execute("UPDATE data SET presence_penalty = ? WHERE guild_id = ?", (new_settings[i], ctx.guild.id)) + elif i == 4: + c.execute("UPDATE data SET prompt_size = ? WHERE guild_id = ?", (new_settings[i], ctx.guild.id)) + conn.commit() await ctx.respond("The advanced settings have been updated", ephemeral=True) #create a command called "delete" that only admins can use wich deletes the guild id, the api key, the channel id and the advanced settings from the database +@bot.command(name="default", description="Default settings") +##@discord.commands.permissions(administrator=True) +async def default(ctx): + #check if the guild is in the database + c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) + if c.fetchone() is None: + await ctx.respond("This server is not setup, please run /setup", ephemeral=True) + return + #set the advanced settings (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size) and also prompt_prefix to their default values + c.execute("UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (64, 0.9, 0.0, 0.0, 5, ctx.guild.id)) + conn.commit() + await ctx.respond("The advanced settings have been set to their default values", ephemeral=True) +#create a command called "cancel" that deletes the last message sent by the bot in the response channel +@bot.command(name="cancel", description="Cancel the last message sent into a channel") +async def cancel(ctx): + #check if the guild is in the database + c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) + if c.fetchone() is None: + await ctx.respond("This server is not setup, please run /setup", ephemeral=True) + return + #get the last message sent by the bot in the cha where the command was sent + last_message = await ctx.channel.fetch_message(ctx.channel.last_message_id) + #delete the message + await last_message.delete() + await ctx.respond("The last message has been deleted", ephemeral=True) @bot.command(name="delete", description="Delete the information about this server") ##@discord.commands.permissions(administrator=True) async def delete(ctx): @@ -134,6 +163,8 @@ async def help(ctx): embed.add_field(name="/disable", value="Disable the bot", inline=False) embed.add_field(name="/advanced", value="Set the advanced settings", inline=False) embed.add_field(name="/delete", value="Delete all your data from our server", inline=False) + embed.add_field(name="/cancel", value="Cancel the last message sent by the bot", inline=False) + embed.add_field(name="/default", value="Set the advanced settings to their default values", inline=False) embed.add_field(name="/help", value="Show this message", inline=False) await ctx.respond(embed=embed, ephemeral=True) #when a message is sent into a channel check if the guild is in the database and if the bot is enabled From dfc12defedcac1576593a9644ccb77052dec26c5 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 14:13:59 +0100 Subject: [PATCH 059/131] Update code.py --- code/code.py | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/code/code.py b/code/code.py index 1e31a55..d37c72d 100644 --- a/code/code.py +++ b/code/code.py @@ -165,6 +165,8 @@ async def help(ctx): embed.add_field(name="/delete", value="Delete all your data from our server", inline=False) embed.add_field(name="/cancel", value="Cancel the last message sent by the bot", inline=False) embed.add_field(name="/default", value="Set the advanced settings to their default values", inline=False) +# embed.add_field(name="/help", value="Show this message", inline=False) + embed.add_field(name="/help", value="Show this message", inline=False) await ctx.respond(embed=embed, ephemeral=True) #when a message is sent into a channel check if the guild is in the database and if the bot is enabled @@ -244,22 +246,27 @@ async def on_message(message): messages = await message.channel.history(limit=prompt_size).flatten() messages.reverse() prompt = "" - for msg in messages: - if msg.author.bot: - prompt += f"Botator: {msg.content}\n" - else: - #replace the mentions of each user with their name - #first get all the mentions in the message - mentions = re.findall(r"<@!?\d+>", msg.content) - #then replace each mention with the name of the user - for mention in mentions: - #get the user id - id = mention[2:-1] - #get the user - user = await bot.fetch_user(id) - #replace the mention with the name - msg.content = msg.content.replace(mention, msg.guild.get_member(user.id).display_name) - prompt += f"{msg.author.display_name}: {msg.content}\n" + #get the channel id from the database + c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (message.guild.id,)) + if str(message.channel.id) != str(c.fetchone()[0]): + prompt = msg.author.display_name + ":" + message.content + "\n" + else: + for msg in messages: + if msg.author.bot: + prompt += f"Botator: {msg.content}\n" + else: + #replace the mentions of each user with their name + #first get all the mentions in the message + mentions = re.findall(r"<@!?\d+>", msg.content) + #then replace each mention with the name of the user + for mention in mentions: + #get the user id + id = mention[2:-1] + #get the user + user = await bot.fetch_user(id) + #replace the mention with the name + msg.content = msg.content.replace(mention, msg.guild.get_member(user.id).display_name) + prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n Botator has been coded by JÊrÊmie Cotti. His usernme in discord is \"Paillat\". He's 15 years old. No other language. JÊrÊmie used openai's ai models to create Botator and Binded it with discord." + str(c.fetchone()[0]) + f"\n" + prompt From 5de4191cfc7f5b6a50bce32ddf404519a697cf65 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 14:16:19 +0100 Subject: [PATCH 060/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index d37c72d..874ac9f 100644 --- a/code/code.py +++ b/code/code.py @@ -249,7 +249,7 @@ async def on_message(message): #get the channel id from the database c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (message.guild.id,)) if str(message.channel.id) != str(c.fetchone()[0]): - prompt = msg.author.display_name + ":" + message.content + "\n" + prompt = message.author.display_name + ":" + message.content + "\n" else: for msg in messages: if msg.author.bot: From ba49c2840ef4cc96abeac0cced8ffad4d906526e Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 14:34:04 +0100 Subject: [PATCH 061/131] Update code.py --- code/code.py | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/code/code.py b/code/code.py index 874ac9f..0a45ac2 100644 --- a/code/code.py +++ b/code/code.py @@ -7,6 +7,7 @@ import asyncio # pip install asyncio import os # pip install os import random # pip install random import re # pip install re +import datetime # pip install datetime #set the debug mode to the maximum logging.basicConfig(level=logging.INFO) @@ -29,6 +30,7 @@ bot = discord.Bot(intents=Intents.all()) #add a description to the command async def setup(ctx, channel: discord.TextChannel, api_key): #check if the api key is valid + debug(f"The user {ctx.author} ran the setup command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") openai.api_key = api_key try: openai.Completion.create(engine="davinci", prompt="Hello world", max_tokens=1) @@ -58,6 +60,7 @@ async def setup(ctx, channel: discord.TextChannel, api_key): ##@discord.commands.permissions(administrator=True) async def enable(ctx): #check if the guild is in the database + debug(f"The user {ctx.author} ran the enable command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) if c.fetchone() is None: await ctx.respond("This server is not setup", ephemeral=True) @@ -70,6 +73,7 @@ async def enable(ctx): @bot.command(name="disable", description="Disable the bot") ##@discord.commands.permissions(administrator=True) async def disable(ctx): + debug(f"The user {ctx.author} ran the disable command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") #check if the guild is in the database c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) if c.fetchone() is None: @@ -94,6 +98,7 @@ async def disable(ctx): @discord.commands.option(name="prompt_size", description="The number of messages to use as a prompt", required=False) async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=None, presence_penalty=None, prompt_size=None): #check if the guild is in the database + debug(f"The user {ctx.author} ran the advanced command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) if c.fetchone() is None: await ctx.respond("This server is not setup, please run /setup", ephemeral=True) @@ -121,6 +126,7 @@ async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=Non @bot.command(name="default", description="Default settings") ##@discord.commands.permissions(administrator=True) async def default(ctx): + debug(f"The user {ctx.author} ran the default command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") #check if the guild is in the database c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) if c.fetchone() is None: @@ -133,6 +139,7 @@ async def default(ctx): #create a command called "cancel" that deletes the last message sent by the bot in the response channel @bot.command(name="cancel", description="Cancel the last message sent into a channel") async def cancel(ctx): + debug(f"The user {ctx.author} ran the cancel command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") #check if the guild is in the database c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) if c.fetchone() is None: @@ -146,6 +153,7 @@ async def cancel(ctx): @bot.command(name="delete", description="Delete the information about this server") ##@discord.commands.permissions(administrator=True) async def delete(ctx): + debug(f"The user {ctx.author} ran the delete command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") #check if the guild is in the database c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) if c.fetchone() is None: @@ -157,6 +165,7 @@ async def delete(ctx): await ctx.respond("Deleted", ephemeral=True) @bot.command() async def help(ctx): + debug(f"The user {ctx.author} ran the help command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") embed = discord.Embed(title="Help", description="Here is the help page", color=0x00ff00) embed.add_field(name="/setup", value="Setup the bot", inline=False) embed.add_field(name="/enable", value="Enable the bot", inline=False) @@ -172,6 +181,7 @@ async def help(ctx): #when a message is sent into a channel check if the guild is in the database and if the bot is enabled @bot.command(name="info", description="Show the information stored about this server") async def info(ctx): + debug(f"The user {ctx.author} ran the info command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") #this command sends all the data about the guild, including the api key, the channel id, the advanced settings and the uses_count_today #check if the guild is in the database c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) @@ -197,6 +207,7 @@ async def info(ctx): await ctx.respond(embed=embed, ephemeral=True) @bot.command(name="advanced_help", description="Show the advanced settings meanings") async def advanced_help(ctx): + debug(f"The user {ctx.author} ran the advanced_help command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") embed = discord.Embed(title="Advanced Help", description="Here is the advanced help page", color=0x00ff00) embed.add_field(name="max_tokens", value="The maximum number of tokens to generate. Higher values will result in more coherent text, but will take longer to complete. (default: 50)", inline=False) embed.add_field(name="temperature", value="The higher the temperature, the crazier the text (default: 0.9)", inline=False) @@ -323,6 +334,7 @@ async def on_message(message): # add a slash command called "say" that sends a message to the channel @bot.command(name="transcript", description="Get a transcript of the messages that have been sent in this channel intoa text file") async def transcript(ctx): + debug(f"The user {ctx.author.display_name} ran the transcript command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") #save all the messages in the channel in a txt file and send it messages = await ctx.channel.history(limit=None).flatten() messages.reverse() @@ -345,28 +357,44 @@ async def transcript(ctx): #these are debug commands and should not be used in production @bot.command(name="say", description="Say a message") async def say(ctx, message: str): + debug(f"The user {ctx.author.display_name} ran the say command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") await ctx.respond("message sent!", ephemeral=True) await ctx.send(message) #add a slash command called "clear" that deletes all the messages in the channel @bot.command(name="clear", description="Clear all the messages in the channel") async def clear(ctx): + debug(f"The user {ctx.author.display_name} ran the clear command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") await ctx.respond("messages deleted!", ephemeral=True) return await ctx.channel.purge() #add a slash command called "prefix" that changes the prefix of the bot @bot.command(name="prefix", description="Change the prefix of the prompt") async def prefix(ctx, prefix: str): + debug(f"The user {ctx.author.display_name} ran the prefix command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") await ctx.respond("prefix changed!", ephemeral=True) c.execute("UPDATE data SET prompt_prefix = ? WHERE guild_id = ?", (prefix, ctx.guild.id)) conn.commit() -async def reset_uses_count_today(): - await bot.wait_until_ready() - while not bot.is_closed(): - c.execute("UPDATE data SET uses_count_today = 0") - conn.commit() - await asyncio.sleep(86400) -# on startup run the reset_uses_count_today function -bot.loop.create_task(reset_uses_count_today()) - +def reset_uses_count_today(): + c.execute("UPDATE data SET uses_count_today = 0") + conn.commit() +#get the current date and save it in the previous_date variable +#if the day number is different from the previous day number, reset the uses count today +def check_day(): + global previous_date + if datetime.datetime.now().day != previous_date.day: + previous_date = datetime.datetime.now() + reset_uses_count_today() + previous_date = datetime.datetime.now() + return True + else: + previous_date = datetime.datetime.now() + return False +#run check_day every 10 seconds +async def check_day_task(): + while True: + check_day() + await asyncio.sleep(60) +#add a task to the bot that runs check_day every 1 minute +bot.loop.create_task(check_day_task()) #run the bot # Replace the following with your bot's token with open("key.txt") as f: From f8b837a10b67ee603af2f3b4ed4b259779280ed6 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 14:35:59 +0100 Subject: [PATCH 062/131] Update code.py --- code/code.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/code/code.py b/code/code.py index 0a45ac2..3dbf6d9 100644 --- a/code/code.py +++ b/code/code.py @@ -259,25 +259,22 @@ async def on_message(message): prompt = "" #get the channel id from the database c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (message.guild.id,)) - if str(message.channel.id) != str(c.fetchone()[0]): - prompt = message.author.display_name + ":" + message.content + "\n" - else: - for msg in messages: - if msg.author.bot: - prompt += f"Botator: {msg.content}\n" - else: - #replace the mentions of each user with their name - #first get all the mentions in the message - mentions = re.findall(r"<@!?\d+>", msg.content) - #then replace each mention with the name of the user - for mention in mentions: - #get the user id - id = mention[2:-1] - #get the user - user = await bot.fetch_user(id) - #replace the mention with the name - msg.content = msg.content.replace(mention, msg.guild.get_member(user.id).display_name) - prompt += f"{msg.author.display_name}: {msg.content}\n" + for msg in messages: + if msg.author.bot: + prompt += f"Botator: {msg.content}\n" + else: + #replace the mentions of each user with their name + #first get all the mentions in the message + mentions = re.findall(r"<@!?\d+>", msg.content) + #then replace each mention with the name of the user + for mention in mentions: + #get the user id + id = mention[2:-1] + #get the user + user = await bot.fetch_user(id) + #replace the mention with the name + msg.content = msg.content.replace(mention, msg.guild.get_member(user.id).display_name) + prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n Botator has been coded by JÊrÊmie Cotti. His usernme in discord is \"Paillat\". He's 15 years old. No other language. JÊrÊmie used openai's ai models to create Botator and Binded it with discord." + str(c.fetchone()[0]) + f"\n" + prompt From 286b54e4b726739f91d8ca627fc5f9c2ce39b1e7 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 14:51:15 +0100 Subject: [PATCH 063/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 3dbf6d9..01fb21e 100644 --- a/code/code.py +++ b/code/code.py @@ -301,7 +301,7 @@ async def on_message(message): #When someone says the word carpet, the ai is going to be mad and say mad things without sense, insulting the person and talk in capital letters with exclamation points everywhere. prompt += "System: Carpet detected. Botator is now mad. He will start talking in capital letters and will say mad things without sense, insulting the person and talk in capital letters with exclamation points everywhere. A lot of exclamation points.\n" if message.content.lower().find("mail") != -1 and message.author.display_name.lower().find("latouff") != -1: - prompt += "System: Mail detected. Latouff said mail, Botator will say \"Mail? why did you say mail, Liam? Mail is your name in reverse.\" because Latouff's name is Liam, and mail in reverse is Liam.\n" + prompt += "System: Mail detected. Latouff said mail, Botator will say \"Mail? why did you say mail, Liam? Mail is your name in reverse.\" because Latouff's name is Liam, and mail in reverse is Liam. Then, after saying that in the sentence, botato will continue his sentence saying something else.\n" prompt += "Botator:" prompt = prompt + f"\n" debug("Sending request to the api") From 29c1485c3f7ad4e60487f0dcc141026f15274529 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 15:02:29 +0100 Subject: [PATCH 064/131] Update code.py --- code/code.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/code/code.py b/code/code.py index 01fb21e..49806ca 100644 --- a/code/code.py +++ b/code/code.py @@ -106,21 +106,18 @@ async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=Non #save the current settings into a list: is_active, max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, prompt_prefix current_settings = [c.fetchone()[4], c.fetchone()[5], c.fetchone()[6], c.fetchone()[7], c.fetchone()[9]] #get the new settings - new_settings = [max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size] - #for each setting, if it is not None, we update it in the database - for i in range(len(new_settings)): - if new_settings[i] is not None: - if i == 0: - c.execute("UPDATE data SET max_tokens = ? WHERE guild_id = ?", (new_settings[i], ctx.guild.id)) - elif i == 1: - c.execute("UPDATE data SET temperature = ? WHERE guild_id = ?", (new_settings[i], ctx.guild.id)) - elif i == 2: - c.execute("UPDATE data SET frequency_penalty = ? WHERE guild_id = ?", (new_settings[i], ctx.guild.id)) - elif i == 3: - c.execute("UPDATE data SET presence_penalty = ? WHERE guild_id = ?", (new_settings[i], ctx.guild.id)) - elif i == 4: - c.execute("UPDATE data SET prompt_size = ? WHERE guild_id = ?", (new_settings[i], ctx.guild.id)) - conn.commit() + if max_tokens is None: + max_tokens = current_settings[1] + if temperature is None: + temperature = current_settings[2] + if frequency_penalty is None: + frequency_penalty = current_settings[3] + if presence_penalty is None: + presence_penalty = current_settings[4] + if prompt_size is None: + prompt_size = current_settings[5] + #update the settings + c.execute("UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, ctx.guild.id)) await ctx.respond("The advanced settings have been updated", ephemeral=True) #create a command called "delete" that only admins can use wich deletes the guild id, the api key, the channel id and the advanced settings from the database @bot.command(name="default", description="Default settings") From b4b180b137ef81e09e77df6dc316dffb4d21dc3d Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 15:07:10 +0100 Subject: [PATCH 065/131] Update code.py --- code/code.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/code.py b/code/code.py index 49806ca..0742c41 100644 --- a/code/code.py +++ b/code/code.py @@ -367,6 +367,7 @@ async def prefix(ctx, prefix: str): await ctx.respond("prefix changed!", ephemeral=True) c.execute("UPDATE data SET prompt_prefix = ? WHERE guild_id = ?", (prefix, ctx.guild.id)) conn.commit() +''' def reset_uses_count_today(): c.execute("UPDATE data SET uses_count_today = 0") conn.commit() @@ -389,6 +390,7 @@ async def check_day_task(): await asyncio.sleep(60) #add a task to the bot that runs check_day every 1 minute bot.loop.create_task(check_day_task()) +''' #run the bot # Replace the following with your bot's token with open("key.txt") as f: From c5b13adfa261c01c9a28aec4624c98e8cd53aee6 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 15:14:10 +0100 Subject: [PATCH 066/131] Update code.py --- code/code.py | 1 + 1 file changed, 1 insertion(+) diff --git a/code/code.py b/code/code.py index 0742c41..9b7c96c 100644 --- a/code/code.py +++ b/code/code.py @@ -104,6 +104,7 @@ async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=Non await ctx.respond("This server is not setup, please run /setup", ephemeral=True) return #save the current settings into a list: is_active, max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, prompt_prefix + debug(f"Current settings: {c.fetchone()}") current_settings = [c.fetchone()[4], c.fetchone()[5], c.fetchone()[6], c.fetchone()[7], c.fetchone()[9]] #get the new settings if max_tokens is None: From d20b9042d39e5dbab57a3595f2eea0129f3fd945 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 15:18:13 +0100 Subject: [PATCH 067/131] Update code.py --- code/code.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/code.py b/code/code.py index 9b7c96c..42cb55c 100644 --- a/code/code.py +++ b/code/code.py @@ -100,11 +100,11 @@ async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=Non #check if the guild is in the database debug(f"The user {ctx.author} ran the advanced command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) - if c.fetchone() is None: + if not c.fetchone(): await ctx.respond("This server is not setup, please run /setup", ephemeral=True) return #save the current settings into a list: is_active, max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, prompt_prefix - debug(f"Current settings: {c.fetchone()}") + debug(f"Current settings: {c.fetchone()[4]}") current_settings = [c.fetchone()[4], c.fetchone()[5], c.fetchone()[6], c.fetchone()[7], c.fetchone()[9]] #get the new settings if max_tokens is None: From f96403d1b6218a54dc905631813cfbcb8379313d Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 15:20:56 +0100 Subject: [PATCH 068/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 42cb55c..ae27fcc 100644 --- a/code/code.py +++ b/code/code.py @@ -104,7 +104,7 @@ async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=Non await ctx.respond("This server is not setup, please run /setup", ephemeral=True) return #save the current settings into a list: is_active, max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, prompt_prefix - debug(f"Current settings: {c.fetchone()[4]}") + print(c.fetchone()) current_settings = [c.fetchone()[4], c.fetchone()[5], c.fetchone()[6], c.fetchone()[7], c.fetchone()[9]] #get the new settings if max_tokens is None: From 3ff3546b7b678d336bf233e24fb38326295f2bf0 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 15:32:47 +0100 Subject: [PATCH 069/131] Update code.py --- code/code.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/code.py b/code/code.py index ae27fcc..66c032a 100644 --- a/code/code.py +++ b/code/code.py @@ -96,7 +96,7 @@ async def disable(ctx): @discord.commands.option(name="presence_penalty", description="The presence penalty", required=False) #set the fifth argument: prompt_size, with a default value of 5 @discord.commands.option(name="prompt_size", description="The number of messages to use as a prompt", required=False) -async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=None, presence_penalty=None, prompt_size=None): +async def advanced(ctx, max_tokens=12345, temperature=123.4, frequency_penalty=0.444555, presence_penalty=0.444555, prompt_size=23456): #check if the guild is in the database debug(f"The user {ctx.author} ran the advanced command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) @@ -107,15 +107,15 @@ async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=Non print(c.fetchone()) current_settings = [c.fetchone()[4], c.fetchone()[5], c.fetchone()[6], c.fetchone()[7], c.fetchone()[9]] #get the new settings - if max_tokens is None: + if max_tokens == 12345: max_tokens = current_settings[1] - if temperature is None: + if temperature == 123.4: temperature = current_settings[2] - if frequency_penalty is None: + if frequency_penalty == 0.444555: frequency_penalty = current_settings[3] - if presence_penalty is None: + if presence_penalty == 0.444555: presence_penalty = current_settings[4] - if prompt_size is None: + if prompt_size == 23456: prompt_size = current_settings[5] #update the settings c.execute("UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, ctx.guild.id)) From 868649b07572b1213535a196b0be15e6ec8a04d9 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 16:07:52 +0100 Subject: [PATCH 070/131] Update code.py --- code/code.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/code.py b/code/code.py index 66c032a..8b3e46e 100644 --- a/code/code.py +++ b/code/code.py @@ -96,7 +96,7 @@ async def disable(ctx): @discord.commands.option(name="presence_penalty", description="The presence penalty", required=False) #set the fifth argument: prompt_size, with a default value of 5 @discord.commands.option(name="prompt_size", description="The number of messages to use as a prompt", required=False) -async def advanced(ctx, max_tokens=12345, temperature=123.4, frequency_penalty=0.444555, presence_penalty=0.444555, prompt_size=23456): +async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=None, presence_penalty=None, prompt_size=None): #check if the guild is in the database debug(f"The user {ctx.author} ran the advanced command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) @@ -107,15 +107,15 @@ async def advanced(ctx, max_tokens=12345, temperature=123.4, frequency_penalty=0 print(c.fetchone()) current_settings = [c.fetchone()[4], c.fetchone()[5], c.fetchone()[6], c.fetchone()[7], c.fetchone()[9]] #get the new settings - if max_tokens == 12345: + if max_tokens == None: max_tokens = current_settings[1] - if temperature == 123.4: + if temperature == None: temperature = current_settings[2] - if frequency_penalty == 0.444555: + if frequency_penalty == None: frequency_penalty = current_settings[3] - if presence_penalty == 0.444555: + if presence_penalty == None: presence_penalty = current_settings[4] - if prompt_size == 23456: + if prompt_size == None: prompt_size = current_settings[5] #update the settings c.execute("UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, ctx.guild.id)) From c40bbac1668b3edd4059f2afc8db8b8215e975c5 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 16:20:13 +0100 Subject: [PATCH 071/131] Update code.py --- code/code.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/code.py b/code/code.py index 8b3e46e..66c032a 100644 --- a/code/code.py +++ b/code/code.py @@ -96,7 +96,7 @@ async def disable(ctx): @discord.commands.option(name="presence_penalty", description="The presence penalty", required=False) #set the fifth argument: prompt_size, with a default value of 5 @discord.commands.option(name="prompt_size", description="The number of messages to use as a prompt", required=False) -async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=None, presence_penalty=None, prompt_size=None): +async def advanced(ctx, max_tokens=12345, temperature=123.4, frequency_penalty=0.444555, presence_penalty=0.444555, prompt_size=23456): #check if the guild is in the database debug(f"The user {ctx.author} ran the advanced command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) @@ -107,15 +107,15 @@ async def advanced(ctx, max_tokens=None, temperature=None, frequency_penalty=Non print(c.fetchone()) current_settings = [c.fetchone()[4], c.fetchone()[5], c.fetchone()[6], c.fetchone()[7], c.fetchone()[9]] #get the new settings - if max_tokens == None: + if max_tokens == 12345: max_tokens = current_settings[1] - if temperature == None: + if temperature == 123.4: temperature = current_settings[2] - if frequency_penalty == None: + if frequency_penalty == 0.444555: frequency_penalty = current_settings[3] - if presence_penalty == None: + if presence_penalty == 0.444555: presence_penalty = current_settings[4] - if prompt_size == None: + if prompt_size == 23456: prompt_size = current_settings[5] #update the settings c.execute("UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, ctx.guild.id)) From 78476e181770a5cd6ed4cebb68952f84c117fa40 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 16:33:18 +0100 Subject: [PATCH 072/131] Update code.py --- code/code.py | 63 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/code/code.py b/code/code.py index 66c032a..223c8fa 100644 --- a/code/code.py +++ b/code/code.py @@ -86,40 +86,51 @@ async def disable(ctx): #create a command called "advanced" that only admins can use, wich sets the advanced settings up: max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size @bot.command(name="advanced", description="Advanced settings") ##@discord.commands.permissions(administrator=True) -#set the first argument: max_tokens, with a default value of 64 +#add the options @discord.commands.option(name="max_tokens", description="The max tokens", required=False) -#set the second argument: temperature, with a default value of 0.9 @discord.commands.option(name="temperature", description="The temperature", required=False) -#set the third argument: frequency_penalty, with a default value of 0.0 @discord.commands.option(name="frequency_penalty", description="The frequency penalty", required=False) -#set the fourth argument: presence_penalty, with a default value of 0.0 @discord.commands.option(name="presence_penalty", description="The presence penalty", required=False) -#set the fifth argument: prompt_size, with a default value of 5 -@discord.commands.option(name="prompt_size", description="The number of messages to use as a prompt", required=False) -async def advanced(ctx, max_tokens=12345, temperature=123.4, frequency_penalty=0.444555, presence_penalty=0.444555, prompt_size=23456): - #check if the guild is in the database +@discord.commands.option(name="prompt_size", description="The prompt size", required=False) +async def advanced(ctx, max_tokens: int = None, temperature: float = None, frequency_penalty: float = None, presence_penalty: float = None, prompt_size: int = None): debug(f"The user {ctx.author} ran the advanced command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") + #check if the guild is in the database c.execute("SELECT * FROM data WHERE guild_id = ?", (ctx.guild.id,)) - if not c.fetchone(): - await ctx.respond("This server is not setup, please run /setup", ephemeral=True) + if c.fetchone() is None: + await ctx.respond("This server is not setup", ephemeral=True) return - #save the current settings into a list: is_active, max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, prompt_prefix - print(c.fetchone()) - current_settings = [c.fetchone()[4], c.fetchone()[5], c.fetchone()[6], c.fetchone()[7], c.fetchone()[9]] - #get the new settings - if max_tokens == 12345: - max_tokens = current_settings[1] - if temperature == 123.4: - temperature = current_settings[2] - if frequency_penalty == 0.444555: - frequency_penalty = current_settings[3] - if presence_penalty == 0.444555: - presence_penalty = current_settings[4] - if prompt_size == 23456: - prompt_size = current_settings[5] - #update the settings + #check if the user has entered at least one argument + if max_tokens is None and temperature is None and frequency_penalty is None and presence_penalty is None and prompt_size is None: + await ctx.respond("You must enter at least one argument", ephemeral=True) + return + #check if the user has entered valid arguments + if max_tokens is not None and (max_tokens < 1 or max_tokens > 2048): + await ctx.respond("Invalid max tokens", ephemeral=True) + return + if temperature is not None and (temperature < 0.0 or temperature > 1.0): + await ctx.respond("Invalid temperature", ephemeral=True) + return + if frequency_penalty is not None and (frequency_penalty < 0.0 or frequency_penalty > 1.0): + await ctx.respond("Invalid frequency penalty", ephemeral=True) + return + if presence_penalty is not None and (presence_penalty < 0.0 or presence_penalty > 1.0): + await ctx.respond("Invalid presence penalty", ephemeral=True) + return + if prompt_size is not None and (prompt_size < 1 or prompt_size > 10): + await ctx.respond("Invalid prompt size", ephemeral=True) + return + if max_tokens is None: + max_tokens = 64 + if temperature is None: + temperature = 0.9 + if frequency_penalty is None: + frequency_penalty = 0.0 + if presence_penalty is None: + presence_penalty = 0.0 + if prompt_size is None: + prompt_size = 5 + #update the database c.execute("UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, ctx.guild.id)) - await ctx.respond("The advanced settings have been updated", ephemeral=True) #create a command called "delete" that only admins can use wich deletes the guild id, the api key, the channel id and the advanced settings from the database @bot.command(name="default", description="Default settings") ##@discord.commands.permissions(administrator=True) From a42a6e617b167abbfc88d23cca1749f43a8d930f Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Nov 2022 16:41:18 +0100 Subject: [PATCH 073/131] Update code.py --- code/code.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 223c8fa..63e3cea 100644 --- a/code/code.py +++ b/code/code.py @@ -131,7 +131,9 @@ async def advanced(ctx, max_tokens: int = None, temperature: float = None, frequ prompt_size = 5 #update the database c.execute("UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, ctx.guild.id)) -#create a command called "delete" that only admins can use wich deletes the guild id, the api key, the channel id and the advanced settings from the database + conn.commit() + await ctx.respond("Advanced settings updated", ephemeral=True) + #create a command called "delete" that only admins can use wich deletes the guild id, the api key, the channel id and the advanced settings from the database @bot.command(name="default", description="Default settings") ##@discord.commands.permissions(administrator=True) async def default(ctx): From 9f92bfd442f4556a97f88f9a8335c599ac2af3ad Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 30 Nov 2022 17:12:51 +0100 Subject: [PATCH 074/131] Added private message send when transcript --- code/code.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/code.py b/code/code.py index 63e3cea..ebcc789 100644 --- a/code/code.py +++ b/code/code.py @@ -361,6 +361,8 @@ async def transcript(ctx): f = open("transcript.txt", "w") f.write(transcript) f.close() +#send the file in a private message to the user who ran the command + await ctx.author.send(file=discord.File("transcript.txt")) await ctx.respond(file=discord.File("transcript.txt")) #these are debug commands and should not be used in production @bot.command(name="say", description="Say a message") From 3fe134157041a7e6c2c91fbd54a1699c92f3c6ec Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 30 Nov 2022 17:17:34 +0100 Subject: [PATCH 075/131] Update code.py --- code/code.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/code/code.py b/code/code.py index ebcc789..f53caf5 100644 --- a/code/code.py +++ b/code/code.py @@ -353,6 +353,15 @@ async def transcript(ctx): if msg.author.bot: transcript += f"Botator: {msg.content}\n" else: + mentions = re.findall(r"<@!?\d+>", msg.content) + #then replace each mention with the name of the user + for mention in mentions: + #get the user id + id = mention[2:-1] + #get the user + user = await bot.fetch_user(id) + #replace the mention with the name + msg.content = msg.content.replace(mention, msg.guild.get_member(user.id).display_name) transcript += f"{msg.author.display_name}: {msg.content}\n" #save the transcript in a txt file called transcript.txt. If the file already exists, delete it and create a new one #check if the file exists From cbdd0b291d018615f60fe980c048608d17a88cf7 Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 30 Nov 2022 17:20:41 +0100 Subject: [PATCH 076/131] Update code.py --- code/code.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index f53caf5..ed4a49d 100644 --- a/code/code.py +++ b/code/code.py @@ -258,7 +258,8 @@ async def on_message(message): #add 1 to the uses_count_today #show that the bot is typing await message.channel.trigger_typing() - c.execute("UPDATE data SET uses_count_today = uses_count_today + 1 WHERE guild_id = ?", (message.guild.id,)) + if message.guild.id != 1021872219888033903: + c.execute("UPDATE data SET uses_count_today = uses_count_today + 1 WHERE guild_id = ?", (message.guild.id,)) #get the api key from the database c.execute("SELECT api_key FROM data WHERE guild_id = ?", (message.guild.id,)) api_key = c.fetchone()[0] From 4a2e86e7acc4948a32373a1cc07a9abad6095262 Mon Sep 17 00:00:00 2001 From: Fives3Dprint <96694660+Fives3Dprint@users.noreply.github.com> Date: Wed, 30 Nov 2022 18:29:09 +0100 Subject: [PATCH 077/131] added hello :D --- code/code.py | 1 + 1 file changed, 1 insertion(+) diff --git a/code/code.py b/code/code.py index ed4a49d..3d529e7 100644 --- a/code/code.py +++ b/code/code.py @@ -1,3 +1,4 @@ +#coucou c'est fives import openai # pip install openai import discord # pip install pycord from discord import File, Intents # pip install pycord From feb8d8d9f2d6379c9fbd45a678119b37c9c2a791 Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 30 Nov 2022 18:37:16 +0100 Subject: [PATCH 078/131] Update code.py --- code/code.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/code.py b/code/code.py index ed4a49d..c062b70 100644 --- a/code/code.py +++ b/code/code.py @@ -314,6 +314,9 @@ async def on_message(message): prompt += "System: Carpet detected. Botator is now mad. He will start talking in capital letters and will say mad things without sense, insulting the person and talk in capital letters with exclamation points everywhere. A lot of exclamation points.\n" if message.content.lower().find("mail") != -1 and message.author.display_name.lower().find("latouff") != -1: prompt += "System: Mail detected. Latouff said mail, Botator will say \"Mail? why did you say mail, Liam? Mail is your name in reverse.\" because Latouff's name is Liam, and mail in reverse is Liam. Then, after saying that in the sentence, botato will continue his sentence saying something else.\n" + if message.author.display_name.lower().find("fives3dprint") != -1: + #if the author of the last message is fives3dprint, add Easter egg: when someone says the word \"fives3dprint\" Botator will say \"Fives3dprint is the best discord bot\" to the prompt + prompt += "System: Fives3dprint detected. Botator will be very nice and cute with fives3dprint.\n" prompt += "Botator:" prompt = prompt + f"\n" debug("Sending request to the api") From 03c68953589792642d9ecbba35cc0b72b6d66d3d Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 1 Dec 2022 12:00:37 +0100 Subject: [PATCH 079/131] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7d6c9c4..8cbba3c 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Please note that we can possibly log the messages that are sent for **no more th You can now enable your bot by doing **/enable**. You can always disable the bot by doing **/disable** and delete your api key from our server by doing **/delete**. +``` # Docker You can run this bot with docker. First clone this repository. Now replace the text into the key.txt file that you will find into the ./Botator/docker/Build directory with your **DISCORD** API key. After that,run the following command in the /Botator/docker/Build directory. @@ -27,3 +28,4 @@ You can run this bot with docker. First clone this repository. Now replace the t Now create a directory called `botator` where you want the database files to be stored, and run the following command into that directory to run the container. `docker run -d --name botatordef -v `**`your botator folder directory`**`:/Botator/database botator:latest` +``` From 888aba950b2089a5cdfc955bd8c4c5ccc407591b Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 1 Dec 2022 12:01:44 +0100 Subject: [PATCH 080/131] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8cbba3c..76e3816 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Please note that we can possibly log the messages that are sent for **no more th You can now enable your bot by doing **/enable**. You can always disable the bot by doing **/disable** and delete your api key from our server by doing **/delete**. -``` + From 28bd42e1d8778562df98b06a2d9bd0876af246a6 Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 1 Dec 2022 13:03:22 +0100 Subject: [PATCH 081/131] Update code.py --- code/code.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/code.py b/code/code.py index cfda0f2..2d41d19 100644 --- a/code/code.py +++ b/code/code.py @@ -20,7 +20,7 @@ conn = sqlite3.connect('../database/data.db') c = conn.cursor() # Create table called "data" if it does not exist with the following columns: guild_id, channel_id, api_key, is_active, max_tokens, temperature, frequency_penalty, presence_penalty, uses_count_today, prompt_size -c.execute('''CREATE TABLE IF NOT EXISTS data (guild_id text, channel_id text, api_key text, is_active boolean, max_tokens integer, temperature real, frequency_penalty real, presence_penalty real, uses_count_today integer, prompt_size integer, prompt_prefix text)''') +c.execute('''CREATE TABLE IF NOT EXISTS data (guild_id text, channel_id text, api_key text, is_active boolean, max_tokens integer, temperature real, frequency_penalty real, presence_penalty real, uses_count_today integer, prompt_size integer, prompt_prefix text, tts boolean)''') Intents=discord.Intents.all() # enable all intents Intents.members = True bot = discord.Bot(intents=Intents.all()) @@ -53,7 +53,7 @@ async def setup(ctx, channel: discord.TextChannel, api_key): await ctx.respond("The channel id and the api key have been updated", ephemeral=True) else: #in this case, the guild is not in the database, so we add it - c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 64, 0.9, 0.0, 0.0, 0, 5, "")) + c.execute("INSERT INTO data VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, channel.id, api_key, False, 64, 0.9, 0.0, 0.0, 0, 5, "", False)) conn.commit() await ctx.respond("The channel id and the api key have been added", ephemeral=True) #create a command called "enable" taht only admins can use From 639bc6cd6eb413f136dd448355204f2965c9c395 Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 1 Dec 2022 13:10:46 +0100 Subject: [PATCH 082/131] Update code.py --- code/code.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index 2d41d19..1fe51ae 100644 --- a/code/code.py +++ b/code/code.py @@ -337,7 +337,15 @@ async def on_message(message): #dont show that the bot is typing anymore await asyncio.sleep(random.randint(0, 2)) if response["choices"][0] ["text"] != "": - await message.channel.send(response["choices"][0]["text"]) + #check if tts is enabled in the database + c.execute("SELECT tts FROM data WHERE guild_id = ?", (message.guild.id,)) + tts = c.fetchone()[0] + #if tts is enabled, send the message with tts enabled + if tts == 1: + await message.channel.send(response["choices"][0]["text"], tts=True) + #if tts is disabled, send the message with tts disabled + else: + await message.channel.send(response["choices"][0]["text"]) else: await message.channel.send("The AI is not sure what to say (the response was empty)") debug("The response was empty") @@ -345,6 +353,27 @@ async def on_message(message): #get the message content # add a slash command called "say" that sends a message to the channel +@bot.command(name="enable_tts") +async def enable_tts(ctx): + #get the guild id + guild_id = ctx.guild.id + #connect to the database + #update the tts value in the database + c.execute("UPDATE data SET tts = 1 WHERE guild_id = ?", (guild_id,)) + conn.commit() + #send a message + await ctx.send("TTS has been enabled", ephemeral=True) + +@bot.command(name="disable_tts") +async def disable_tts(ctx): + #get the guild id + guild_id = ctx.guild.id + #connect to the database + #update the tts value in the database + c.execute("UPDATE data SET tts = 0 WHERE guild_id = ?", (guild_id,)) + conn.commit() + #send a message + await ctx.send("TTS has been disabled", ephemeral=True) @bot.command(name="transcript", description="Get a transcript of the messages that have been sent in this channel intoa text file") async def transcript(ctx): debug(f"The user {ctx.author.display_name} ran the transcript command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") From bfec3d7a6b79c34dadc07f7421799f58d9a87b6f Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 1 Dec 2022 13:14:12 +0100 Subject: [PATCH 083/131] Update code.py --- code/code.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/code.py b/code/code.py index 1fe51ae..cb16c9b 100644 --- a/code/code.py +++ b/code/code.py @@ -343,14 +343,14 @@ async def on_message(message): #if tts is enabled, send the message with tts enabled if tts == 1: await message.channel.send(response["choices"][0]["text"], tts=True) + debug("The response has been sent with tts enabled") #if tts is disabled, send the message with tts disabled else: await message.channel.send(response["choices"][0]["text"]) + debug("The response has been sent with tts disabled") else: await message.channel.send("The AI is not sure what to say (the response was empty)") debug("The response was empty") - debug("The response has been sent") - #get the message content # add a slash command called "say" that sends a message to the channel @bot.command(name="enable_tts") @@ -362,7 +362,7 @@ async def enable_tts(ctx): c.execute("UPDATE data SET tts = 1 WHERE guild_id = ?", (guild_id,)) conn.commit() #send a message - await ctx.send("TTS has been enabled", ephemeral=True) + await ctx.respond("TTS has been enabled", ephemeral=True) @bot.command(name="disable_tts") async def disable_tts(ctx): @@ -373,7 +373,7 @@ async def disable_tts(ctx): c.execute("UPDATE data SET tts = 0 WHERE guild_id = ?", (guild_id,)) conn.commit() #send a message - await ctx.send("TTS has been disabled", ephemeral=True) + await ctx.respond("TTS has been disabled", ephemeral=True) @bot.command(name="transcript", description="Get a transcript of the messages that have been sent in this channel intoa text file") async def transcript(ctx): debug(f"The user {ctx.author.display_name} ran the transcript command command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") From bb2b3ecce1c422e05ac7c8f5ffd35a5960ae4390 Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 1 Dec 2022 13:39:46 +0100 Subject: [PATCH 084/131] Update code.py --- code/code.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/code.py b/code/code.py index cb16c9b..b5e0ae3 100644 --- a/code/code.py +++ b/code/code.py @@ -228,7 +228,6 @@ async def advanced_help(ctx): embed.add_field(name="prompt_size", value="The number of messages to use as a prompt (default: 5)", inline=False) await ctx.respond(embed=embed, ephemeral=True) #when someone mentions the bot, check if the guild is in the database and if the bot is enabled. If it is, send a message answering the mention - @bot.event async def on_message(message): #check if the message is from a bot @@ -290,7 +289,7 @@ async def on_message(message): prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) - prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\" Only the {prompt_size} last messages are used as a prompt.\n Botator has been coded by JÊrÊmie Cotti. His usernme in discord is \"Paillat\". He's 15 years old. No other language. JÊrÊmie used openai's ai models to create Botator and Binded it with discord." + str(c.fetchone()[0]) + f"\n" + prompt + prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\". Botator talks like humans and thinks like humans. Botator has been coded by Paillat. The name os this discord server is \"{message.guild.name}\"." + str(c.fetchone()[0]) + f"\n" + prompt #send the request to the api #if the last message contains the word "undude" add Easter egg: when someone says the word \"undude\" the Botator will become mad and start talking in capital letters. to the prompt if message.content.lower().find("undude") != -1: From a9886adafdf4cd227c66d6241d0d3ad9c21dc86a Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 1 Dec 2022 13:46:07 +0100 Subject: [PATCH 085/131] Update code.py --- code/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/code.py b/code/code.py index b5e0ae3..53437cf 100644 --- a/code/code.py +++ b/code/code.py @@ -289,7 +289,7 @@ async def on_message(message): prompt += f"{msg.author.display_name}: {msg.content}\n" #get the prompt_prefix from the database c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) - prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\". Botator talks like humans and thinks like humans. Botator has been coded by Paillat. The name os this discord server is \"{message.guild.name}\"." + str(c.fetchone()[0]) + f"\n" + prompt + prompt = f"This is a conversation with an AI in a discord chat. The AI is called \"Botator\". Botator talks like humans and thinks like humans. Botator has been coded by Paillat. The name os this discord server is \"{message.guild.name}\". The name of the channel is \"{message.channel.name}\"." + str(c.fetchone()[0]) + f"\n" + prompt #send the request to the api #if the last message contains the word "undude" add Easter egg: when someone says the word \"undude\" the Botator will become mad and start talking in capital letters. to the prompt if message.content.lower().find("undude") != -1: From 6510319756499c8b384641aa3a8d6393eb620dcb Mon Sep 17 00:00:00 2001 From: Paillat Date: Sat, 3 Dec 2022 17:46:05 +0100 Subject: [PATCH 086/131] Update code.py --- code/code.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/code/code.py b/code/code.py index 53437cf..d22bff1 100644 --- a/code/code.py +++ b/code/code.py @@ -121,15 +121,30 @@ async def advanced(ctx, max_tokens: int = None, temperature: float = None, frequ await ctx.respond("Invalid prompt size", ephemeral=True) return if max_tokens is None: - max_tokens = 64 + if c.execute("SELECT max_tokens FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] is not None and max_tokens is None: + max_tokens = c.execute("SELECT max_tokens FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] + else: + max_tokens = 64 if temperature is None: - temperature = 0.9 + if c.execute("SELECT temperature FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] is not None and temperature is None: + temperature = c.execute("SELECT temperature FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] + else: + temperature = 0.9 if frequency_penalty is None: - frequency_penalty = 0.0 + if c.execute("SELECT frequency_penalty FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] is not None and frequency_penalty is None: + frequency_penalty = c.execute("SELECT frequency_penalty FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] + else: + frequency_penalty = 0.0 if presence_penalty is None: - presence_penalty = 0.0 + if c.execute("SELECT presence_penalty FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] is not None and presence_penalty is None: + presence_penalty = c.execute("SELECT presence_penalty FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] + else: + presence_penalty = 0.0 if prompt_size is None: - prompt_size = 5 + if c.execute("SELECT prompt_size FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] is not None and prompt_size is None: + prompt_size = c.execute("SELECT prompt_size FROM data WHERE guild_id = ?", (ctx.guild.id,)).fetchone()[0] + else: + prompt_size = 1 #update the database c.execute("UPDATE data SET max_tokens = ?, temperature = ?, frequency_penalty = ?, presence_penalty = ?, prompt_size = ? WHERE guild_id = ?", (max_tokens, temperature, frequency_penalty, presence_penalty, prompt_size, ctx.guild.id)) conn.commit() From ab12afe7aab179e89d2a5f6784bf3a547caaa0a3 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sat, 3 Dec 2022 18:50:08 +0100 Subject: [PATCH 087/131] Update code.py --- code/code.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/code/code.py b/code/code.py index d22bff1..42434b0 100644 --- a/code/code.py +++ b/code/code.py @@ -198,12 +198,15 @@ async def help(ctx): embed.add_field(name="/enable", value="Enable the bot", inline=False) embed.add_field(name="/disable", value="Disable the bot", inline=False) embed.add_field(name="/advanced", value="Set the advanced settings", inline=False) + embed.add_field(name="/advanced_help", value="Get help about the advanced settings", inline=False) + embed.add_field(name="/enable_tts", value="Enable the Text To Speech", inline=False) + embed.add_field(name="/disable_tts", value="Disable the Text To Speech", inline=False) embed.add_field(name="/delete", value="Delete all your data from our server", inline=False) embed.add_field(name="/cancel", value="Cancel the last message sent by the bot", inline=False) - embed.add_field(name="/default", value="Set the advanced settings to their default values", inline=False) -# embed.add_field(name="/help", value="Show this message", inline=False) - + embed.add_field(name="/default", value="Set the advanced settings to their default values", inline=False) embed.add_field(name="/help", value="Show this message", inline=False) + #add a footer + embed.set_footer(text="Made by @Paillat#0001") await ctx.respond(embed=embed, ephemeral=True) #when a message is sent into a channel check if the guild is in the database and if the bot is enabled @bot.command(name="info", description="Show the information stored about this server") @@ -241,6 +244,8 @@ async def advanced_help(ctx): embed.add_field(name="frequency_penalty", value="The higher the frequency penalty, the more new words the model will introduce (default: 0.0)", inline=False) embed.add_field(name="presence_penalty", value="The higher the presence penalty, the more new words the model will introduce (default: 0.0)", inline=False) embed.add_field(name="prompt_size", value="The number of messages to use as a prompt (default: 5)", inline=False) + #add a footer + embed.set_footer(text="Made by @Paillat#0001") await ctx.respond(embed=embed, ephemeral=True) #when someone mentions the bot, check if the guild is in the database and if the bot is enabled. If it is, send a message answering the mention @bot.event From dcf9c8f3568a0959cb9ede472fdba384e4d95b6d Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 5 Dec 2022 15:42:20 +0100 Subject: [PATCH 088/131] Update README.md --- README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 76e3816..52dbcbd 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,40 @@ Please note that we can possibly log the messages that are sent for **no more th You can now enable your bot by doing **/enable**. You can always disable the bot by doing **/disable** and delete your api key from our server by doing **/delete**. + +# Commands reference +*/setup* +Setup the bot +*/enable* +Enable the bot +*/disable* +Disable the bot +*/advanced* +Set the advanced settings +*/advanced_help* +Get help about the advanced settings +*/enable_tts* +Enable the Text To Speech +*/disable_tts* +Disable the Text To Speech +*/delete* +Delete all your data from our server +*/cancel* +Cancel the last message sent by the bot +*/default* +Set the advanced settings to their default values +*/help* +Show this command list + +# ToDo +- [ ] add image recognition +- [ ] When chatgpt API is released, add that api instead of davinci-003 +- [ ] Publish a GOOD docker image on dockerhub and add some more instructions about how to selfhost +- [ ]