🐛 fix(makeprompt.py): reverse the order of fetched messages to ensure correct chronological order

🔥 chore(makeprompt.py): remove unnecessary oldest_first parameter in channel.history() calls
This commit is contained in:
2023-08-15 11:33:29 +02:00
parent 1e8eaf5ae0
commit 68ff639f27

View File

@@ -39,19 +39,20 @@ def is_ignorable(content):
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):
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
else: else:
async for msg in channel.history( async for msg in channel.history(
limit=100, before=original_message, oldest_first=True limit=100, before=original_message
): ):
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
messages.reverse()
return messages return messages
@@ -142,6 +143,7 @@ async def chatgpt_process(
functions=called_functions, functions=called_functions,
# function_call="auto", # function_call="auto",
) )
print(msgs)
response = response["choices"][0]["message"] # type: ignore response = response["choices"][0]["message"] # type: ignore
if response.get("function_call"): if response.get("function_call"):
function_call = response.get("function_call") function_call = response.get("function_call")