Update code.py

This commit is contained in:
Paillat
2022-11-29 14:13:59 +01:00
parent 486fb52ff6
commit dfc12defed

View File

@@ -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="/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="/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="/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) embed.add_field(name="/help", value="Show this message", inline=False)
await ctx.respond(embed=embed, ephemeral=True) 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 #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 = await message.channel.history(limit=prompt_size).flatten()
messages.reverse() messages.reverse()
prompt = "" prompt = ""
for msg in messages: #get the channel id from the database
if msg.author.bot: c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (message.guild.id,))
prompt += f"Botator: {msg.content}\n" if str(message.channel.id) != str(c.fetchone()[0]):
else: prompt = msg.author.display_name + ":" + message.content + "\n"
#replace the mentions of each user with their name else:
#first get all the mentions in the message for msg in messages:
mentions = re.findall(r"<@!?\d+>", msg.content) if msg.author.bot:
#then replace each mention with the name of the user prompt += f"Botator: {msg.content}\n"
for mention in mentions: else:
#get the user id #replace the mentions of each user with their name
id = mention[2:-1] #first get all the mentions in the message
#get the user mentions = re.findall(r"<@!?\d+>", msg.content)
user = await bot.fetch_user(id) #then replace each mention with the name of the user
#replace the mention with the name for mention in mentions:
msg.content = msg.content.replace(mention, msg.guild.get_member(user.id).display_name) #get the user id
prompt += f"{msg.author.display_name}: {msg.content}\n" 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 #get the prompt_prefix from the database
c.execute("SELECT prompt_prefix FROM data WHERE guild_id = ?", (message.guild.id,)) 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\" 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