Update code.py

This commit is contained in:
Paillat
2022-11-29 13:18:40 +01:00
parent 95f73275b3
commit a6fc4bb836

View File

@@ -6,6 +6,7 @@ import sqlite3 # pip install sqlite3
import asyncio # pip install asyncio import asyncio # pip install asyncio
import os # pip install os import os # pip install os
import random # pip install random import random # pip install random
import re # pip install re
#set the debug mode to the maximum #set the debug mode to the maximum
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
@@ -188,6 +189,9 @@ async def on_message(message):
#check if the message has been sent in the channel set in the database #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,)) c.execute("SELECT channel_id FROM data WHERE guild_id = ?", (message.guild.id,))
if str(message.channel.id) != str(c.fetchone()[0]): if str(message.channel.id) != str(c.fetchone()[0]):
if message.content.find(bot.user.mention):
debug("wrong channel, but mention")
else :
debug("The message has been sent in the wrong channel") debug("The message has been sent in the wrong channel")
return return
#check if the bot hasn't been used more than 200 times in the last 24 hours (uses_count_today) #check if the bot hasn't been used more than 200 times in the last 24 hours (uses_count_today)
@@ -213,6 +217,17 @@ async def on_message(message):
if msg.author.bot: if msg.author.bot:
prompt += f"Botator: {msg.content}\n" prompt += f"Botator: {msg.content}\n"
else: 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" 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,))
@@ -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. #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 += "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: 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 += "Botator:"
prompt = prompt + f"\n" prompt = prompt + f"\n"
debug("Sending request to the api") debug("Sending request to the api")