main
Stef Dunlap 2023-03-09 17:29:05 -05:00
parent 22d0b8a412
commit 6ab972368a
1 changed files with 4 additions and 3 deletions

View File

@ -1,5 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
//IRC bot that responds to !chat, queries the chatgpt api, and prints the response line by line //IRC bot that responds to !chat, queries the chatgpt api, and prints the response line by line
const fs = require('fs');
const irc = require('irc'); const irc = require('irc');
const axios = require('axios'); const axios = require('axios');
const config = require('./config.json'); const config = require('./config.json');
@ -51,9 +52,9 @@ class Context {
} }
} }
let context = new Context(savedMessages); let context = null;
if (fs.existsSync('./messages.json')) { if (fs.existsSync('./messages.json')) {
savedMessages = require('./messages.json'); const savedMessages = require('./messages.json');
context = new Context(savedMessages); context = new Context(savedMessages);
} else { } else {
context = new Context(seed_messages); context = new Context(seed_messages);
@ -76,7 +77,7 @@ client.addListener('message', async (from, to, message) => {
if(is_chat_cmd && !config.alwaysRemember) { if(is_chat_cmd && !config.alwaysRemember) {
context.clear(); context.clear();
} }
context.add_user_prompt(query); context.add_user_prompt(message);
const query = message.slice(6); const query = message.slice(6);
try { try {
await chatgpt(query, context.messages, handleChatGPTResponseLine); await chatgpt(query, context.messages, handleChatGPTResponseLine);