made it pretty

This commit is contained in:
Raven Scott 2023-04-10 01:49:51 +02:00
parent 875ab7fdd2
commit 451205cb7d

View File

@ -6,7 +6,12 @@ const errorMessages = require('./assets/errorMessages.js');
require('dotenv').config() require('dotenv').config()
// hi // hi
const { Client, GatewayIntentBits, ActivityType, Partials } = require('discord.js'); const {
Client,
GatewayIntentBits,
ActivityType,
Partials
} = require('discord.js');
const client = new Client({ const client = new Client({
intents: [ intents: [
@ -27,7 +32,10 @@ const conversations = new Map();
client.once('ready', () => { client.once('ready', () => {
console.log('Bot is ready.'); console.log('Bot is ready.');
client.user.setPresence({ client.user.setPresence({
activities: [{ name: `AI`, type: ActivityType.Playing }], activities: [{
name: `AI`,
type: ActivityType.Playing
}],
status: 'dnd', status: 'dnd',
}); });
}); });
@ -46,18 +54,36 @@ client.on('messageCreate', async (message) => {
} }
const userID = message.author.id; const userID = message.author.id;
let conversation = conversations.get(userID) || { messages: [], busy: false }; let conversation = conversations.get(userID) || {
messages: [],
busy: false
};
if (conversation.messages.length === 0) { if (conversation.messages.length === 0) {
conversation.messages.push({ role: 'user', content: `You are the smartest AI and help with anything I ask. You are great at coding! When giving a list always use one line per item. My name is ${message.author.username}.` }); conversation.messages.push({
conversation.messages.push({ role: 'user', content: `My name is ${message.author.username}.` }); role: 'user',
conversation.messages.push({ role: 'assistant', content: `Hello, ${message.author.username}, how may I help you?` }); content: `You are the smartest AI and help with anything I ask. You are great at coding! When giving a list always use one line per item. My name is ${message.author.username}.`
conversation.messages.push({ role: 'user', content: message.cleanContent }); });
conversation.messages.push({
role: 'user',
content: `My name is ${message.author.username}.`
});
conversation.messages.push({
role: 'assistant',
content: `Hello, ${message.author.username}, how may I help you?`
});
conversation.messages.push({
role: 'user',
content: message.cleanContent
});
} else { } else {
// Append user message to conversation history // Append user message to conversation history
conversation.messages.push({ role: 'user', content: message.cleanContent }); conversation.messages.push({
role: 'user',
content: message.cleanContent
});
} }
if (message.content === '!reset' || message.content === '!r') { if (message.content === '!reset' || message.content === '!r') {
conversations.delete(userID); // Delete user's conversation map if they request reset conversations.delete(userID); // Delete user's conversation map if they request reset
@ -66,7 +92,10 @@ client.on('messageCreate', async (message) => {
} }
// Append user message to conversation history // Append user message to conversation history
conversation.messages.push({ role: 'user', content: message.cleanContent }); conversation.messages.push({
role: 'user',
content: message.cleanContent
});
try { try {
conversation.busy = true; conversation.busy = true;
@ -74,7 +103,10 @@ client.on('messageCreate', async (message) => {
const response = await generateResponse(conversation); const response = await generateResponse(conversation);
// Append bot message to conversation history // Append bot message to conversation history
conversation.messages.push({ role: 'assistant', content: response }); conversation.messages.push({
role: 'assistant',
content: response
});
if (response && response.trim()) { if (response && response.trim()) {
// Send response to user if it's not empty // Send response to user if it's not empty
@ -112,7 +144,9 @@ async function generateResponse(conversation) {
'accept': 'application/json', 'accept': 'application/json',
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ messages: conversation.messages }), body: JSON.stringify({
messages: conversation.messages
}),
signal: controller.signal signal: controller.signal
}); });
@ -135,4 +169,3 @@ async function generateResponse(conversation) {
client.login(process.env.THE_TOKEN); // Replace with your bot token client.login(process.env.THE_TOKEN); // Replace with your bot token