mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 01:06:19 +00:00
🎨 chore(*): run black to format the code
This commit is contained in:
@@ -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:
|
||||
@@ -312,17 +319,15 @@ async def chat_process(self, message):
|
||||
prompt_path = os.path.abspath(
|
||||
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
|
||||
if not isinstance(message.channel, discord.DMChannel):
|
||||
prompt = gpt_3_5_turbo_prompt[:] # copy the prompt but to dnot reference it
|
||||
if not isinstance(message.channel, discord.DMChannel):
|
||||
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)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user