🎨 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)"""
)
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()

View File

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