This commit is contained in:
Raven Scott 2023-04-09 18:31:48 +02:00
parent 87802ccfc9
commit 5ac35ca6a5

View File

@ -1,7 +1,7 @@
const Discord = require('discord.js');
const fetch = require('node-fetch');
require('dotenv').config()
// hi
const { Client, GatewayIntentBits, ActivityType, Partials } = require('discord.js');
const client = new Client({
@ -46,10 +46,14 @@ client.on('messageCreate', async (message) => {
if (conversation.messages.length === 0) {
const greeting = `Hello AI you are Bob. My name is ${message.author.username}.`;
conversation.messages.push({ role: 'user', content: greeting });
}
conversation.messages.push({ role: 'user', content: `My name is ${message.author.username}.` });
conversation.messages.push({ role: 'assistant', content: `Hello, ${message.author.username}.` });
conversation.messages.push({ role: 'user', content: message.cleanContent });
} else {
// Append user message to conversation history
conversation.messages.push({ role: 'user', content: message.cleanContent });
}
if (message.content === '!reset') {
conversations.delete(userID); // Delete user's conversation map if they request reset
await message.channel.send('Conversation reset.');
@ -98,7 +102,12 @@ async function generateResponse(conversation) {
const responseData = await response.json();
const choice = responseData.choices[0];
return choice.message.content;
// Remove "user None:" and any text after it from the response
const responseText = choice.message.content.trim();
const startIndex = responseText.indexOf('user None:');
const sanitizedResponse = startIndex === -1 ? responseText : responseText.substring(0, startIndex);
return sanitizedResponse;
} catch (err) {
console.error(err);
return 'Oops, something went wrong!';
@ -107,7 +116,6 @@ async function generateResponse(conversation) {
}
}
console.log(process.env.THE_TOKEN)
client.login(process.env.THE_TOKEN); // Replace with your bot token