Update
This commit is contained in:
parent
c03d4a6043
commit
c7d6a9c4a8
1 changed files with 38 additions and 12 deletions
|
@ -11,6 +11,7 @@ const { moderation } = require('../configs/moderation');
|
||||||
const { chatbot } = require('../configs/chatbot');
|
const { chatbot } = require('../configs/chatbot');
|
||||||
const conversations = new Map();
|
const conversations = new Map();
|
||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
const { exec } = require('child_process');
|
||||||
|
|
||||||
// Load the knowledge from the completion.txt file
|
// Load the knowledge from the completion.txt file
|
||||||
const knowledge = fs.readFileSync(path.join(__dirname, '../utils/prompts/completion.txt'), 'utf-8');
|
const knowledge = fs.readFileSync(path.join(__dirname, '../utils/prompts/completion.txt'), 'utf-8');
|
||||||
|
@ -324,18 +325,43 @@ if (chatbot.State && (chatbot.AllowedChannels.includes(message.channel.name) ||
|
||||||
fullAnswer += part.choices[0]?.delta?.content || '';
|
fullAnswer += part.choices[0]?.delta?.content || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before sending the response, check for mentions
|
const fs = require('fs');
|
||||||
if (!fullAnswer.includes('@everyone') && !fullAnswer.includes('@here') && !fullAnswer.includes('@')) {
|
const { exec } = require('child_process');
|
||||||
if (fullAnswer.length <= 2000) {
|
|
||||||
await message.channel.send(fullAnswer);
|
// Function to restart the bot
|
||||||
} else {
|
function restartBot() {
|
||||||
const embed = new EmbedBuilder()
|
console.log("Restarting bot...");
|
||||||
.setTitle('Response from GPT-4o')
|
process.exit(0); // Exits the current process, assuming your process manager restarts the bot
|
||||||
.setDescription(fullAnswer.substring(0, 4096)) // Embed description has a 4096 character limit
|
}
|
||||||
.setColor('#0099ff');
|
|
||||||
|
// Before sending the response, check for mentions
|
||||||
|
if (!fullAnswer.includes('@everyone') && !fullAnswer.includes('@here') && !fullAnswer.includes('@')) {
|
||||||
|
if (fullAnswer.length <= 2000) {
|
||||||
|
await message.channel.send(fullAnswer);
|
||||||
|
} else if (fullAnswer.length <= 4096) {
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setTitle('Response from GPT-4o')
|
||||||
|
.setDescription(fullAnswer.substring(0, 4096)) // Embed description has a 4096 character limit
|
||||||
|
.setColor('#0099ff');
|
||||||
|
|
||||||
|
await message.channel.send({ embeds: [embed] });
|
||||||
|
} else {
|
||||||
|
// Save the full answer to a .txt file
|
||||||
|
fs.writeFileSync('response.txt', fullAnswer);
|
||||||
|
|
||||||
|
// Send the .txt file
|
||||||
|
await message.channel.send({
|
||||||
|
files: [{
|
||||||
|
attachment: 'response.txt',
|
||||||
|
name: 'response.txt'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
// Restart the bot
|
||||||
|
restartBot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await message.channel.send({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the conversation for self-learning
|
// Save the conversation for self-learning
|
||||||
const conversation = {
|
const conversation = {
|
||||||
|
@ -459,7 +485,7 @@ function shouldRespond(message) {
|
||||||
// Add more conditions as needed based on personality and surroundings
|
// Add more conditions as needed based on personality and surroundings
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue