mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 09:16:19 +00:00
🎨 chore(*): run black to format the code
This commit is contained in:
@@ -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()
|
||||||
@@ -29,12 +29,14 @@ 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:
|
||||||
async for msg in channel.history(limit=100, oldest_first=True):
|
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:
|
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:
|
||||||
@@ -312,17 +319,15 @@ async def chat_process(self, message):
|
|||||||
prompt_path = os.path.abspath(
|
prompt_path = os.path.abspath(
|
||||||
os.path.join(os.path.dirname(__file__), f"./prompts/{model}.txt")
|
os.path.join(os.path.dirname(__file__), f"./prompts/{model}.txt")
|
||||||
)
|
)
|
||||||
prompt = gpt_3_5_turbo_prompt[:] # copy the prompt but to dnot reference it
|
prompt = gpt_3_5_turbo_prompt[:] # copy the prompt but to dnot reference it
|
||||||
if not isinstance(message.channel, discord.DMChannel):
|
if not isinstance(message.channel, discord.DMChannel):
|
||||||
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)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user