chore: Refactor message processing logic and split output into chunks

Refactor the `process_message` function in `bot.py` to improve performance and handle longer messages. The function now appends extra characters to the base message to ensure it is always 4000 characters long. This change improves the processing of messages and prevents truncation.

In `messageCreate.js`, split the output into chunks of 2000 characters using the `splitMessage` function. This allows sending each part as a separate message, ensuring that the output is not cut off.
This commit is contained in:
Bildcraft1 2024-06-06 10:19:06 +02:00
parent c1b886a226
commit 74b3f53212
2 changed files with 29 additions and 7 deletions

5
bot.py
View file

@ -1,8 +1,9 @@
import sys import sys
def process_message(message): def process_message(message):
# Replace this with your actual processing logic base_message = f"Processed message: {message}"
return f"Processed message: {message}" extra_chars = 'a' * (4000 - len(base_message))
return base_message + extra_chars
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) > 1: if len(sys.argv) > 1:

View file

@ -37,15 +37,36 @@ module.exports = {
return message.reply("There was an error processing your request."); return message.reply("There was an error processing your request.");
} }
// Log the output from the Python script let output = stdout.trim();
logAction(`GPT: ${stdout.trim()}`, message.author.id, message.author.tag);
// Reply with the output from the Python script // Log the output from the Python script
message.reply(stdout.trim()); logAction(`GPT: ${output}`, message.author.id, message.author.tag);
// Function to split the output into chunks of 2000 characters
function splitMessage(message, maxLength) {
const parts = [];
while (message.length > 0) {
if (message.length > maxLength) {
parts.push(message.slice(0, maxLength));
message = message.slice(maxLength);
} else {
parts.push(message);
message = '';
}
}
return parts;
}
// Split the output if it's longer than 2000 characters
const maxMessageLength = 2000;
const messageParts = splitMessage(output, maxMessageLength);
// Send each part as a separate message
messageParts.forEach(part => message.reply(part));
}); });
} else { } else {
message.reply("Not whitelisted"); message.reply("Not whitelisted");
} }
} }
}, },
}; }