🎨 chore(*): run black to format the code

This commit is contained in:
2023-08-15 11:04:33 +02:00
parent 8486453d18
commit f04a04801b
2 changed files with 24 additions and 17 deletions

View File

@@ -101,5 +101,9 @@ curs_premium.execute(
"""CREATE TABLE IF NOT EXISTS channels (guild_id text, channel0 text, channel1 text, channel2 text, channel3 text, channel4 text)""" """CREATE TABLE IF NOT EXISTS channels (guild_id text, channel0 text, channel1 text, channel2 text, channel3 text, channel4 text)"""
) )
with open(os.path.abspath(os.path.dirname(__file__), "./prompts/gpt-3.5-turbo.txt"), "r", encoding="utf-8") as file: with open(
os.path.abspath(os.path.dirname(__file__), "./prompts/gpt-3.5-turbo.txt"),
"r",
encoding="utf-8",
) as file:
gpt_3_5_turbo_prompt = file.read() gpt_3_5_turbo_prompt = file.read()

View File

@@ -29,11 +29,13 @@ async def replace_mentions(content, bot):
content = content.replace(mention, f"@{user.name}") content = content.replace(mention, f"@{user.name}")
return content return content
def is_ignorable(content): def is_ignorable(content):
if content.startswith("-") or content.startswith("//"): if content.startswith("-") or content.startswith("//"):
return True return True
return False return False
async def fetch_messages_history(channel: discord.TextChannel, limit, original_message): async def fetch_messages_history(channel: discord.TextChannel, limit, original_message):
messages = [] messages = []
if original_message == None: if original_message == None:
@@ -43,13 +45,16 @@ async def fetch_messages_history(channel:discord.TextChannel, limit, original_me
if len(messages) == limit: if len(messages) == limit:
break break
else: else:
async for msg in channel.history(limit=100, before=original_message, oldest_first=True): async for msg in channel.history(
limit=100, before=original_message, oldest_first=True
):
if not is_ignorable(msg.content): if not is_ignorable(msg.content):
messages.append(msg) messages.append(msg)
if len(messages) == limit: if len(messages) == limit:
break break
return messages return messages
async def chatgpt_process( async def chatgpt_process(
self, messages, message: discord.Message, api_key, prompt, model self, messages, message: discord.Message, api_key, prompt, model
): ):
@@ -294,7 +299,9 @@ async def chat_process(self, message):
except: except:
pass pass
messages = await fetch_messages_history(message.channel, prompt_size, original_message) messages = await fetch_messages_history(
message.channel, prompt_size, original_message
)
# if the pretend to be feature is enabled, we add the pretend to be text to the prompt # if the pretend to be feature is enabled, we add the pretend to be text to the prompt
if pretend_enabled: if pretend_enabled:
@@ -317,12 +324,10 @@ async def chat_process(self, message):
prompt = ( prompt = (
prompt.replace("[prompt-prefix]", prompt_prefix) prompt.replace("[prompt-prefix]", prompt_prefix)
.replace("[server-name]", message.guild.name) .replace("[server-name]", message.guild.name)
.replace("[channel-name]", message.channel.name)
.replace( .replace(
"[channel-name]", "[date-and-time]",
message.channel.name datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S"),
)
.replace(
"[date-and-time]", datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S")
) )
.replace("[pretend-to-be]", pretend_to_be) .replace("[pretend-to-be]", pretend_to_be)
) )
@@ -330,12 +335,10 @@ async def chat_process(self, message):
prompt = ( prompt = (
prompt.replace("[prompt-prefix]", prompt_prefix) prompt.replace("[prompt-prefix]", prompt_prefix)
.replace("[server-name]", "DM-channel") .replace("[server-name]", "DM-channel")
.replace("[channel-name]", "DM-channel")
.replace( .replace(
"[channel-name]", "[date-and-time]",
"DM-channel" datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S"),
)
.replace(
"[date-and-time]", datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S")
) )
.replace("[pretend-to-be]", pretend_to_be) .replace("[pretend-to-be]", pretend_to_be)
) )