handlechat chagnes
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 25s

This commit is contained in:
roberts 2025-05-10 19:52:53 -05:00
parent 37ee4a0ac1
commit 2b5d49d5bc

View file

@ -3,7 +3,7 @@ const path = require('path');
const fs = require('fs');
const { getLastChat, getBot, getDB, setActiveTask, clearActiveTask } = require('../core/context');
const { logChatMessage } = require('../memory/chat');
const { chatWithAI } = require('../lib/ai-helper');
const { chatWithAI, generateAndSaveTask } = require('../lib/ai-helper');
const config = require('../config.json');
module.exports = async function HandleChat() {
@ -38,21 +38,27 @@ module.exports = async function HandleChat() {
}
}
const prompt = `Player said: "${message}". If this is a command, what task name (like 'find-flower', 'chop-tree') would you execute? Otherwise, reply 'none'.`;
const prompt = `Player said: "${message}". What task name should I execute (like 'find-flower', 'move-items')? Reply only with the task name or "none".`;
const aiResponse = await chatWithAI(prompt, config.ai);
const aiTask = aiResponse.trim().toLowerCase().replace(/\s+/g, '-');
if (aiTask !== 'none' && availableTasks.includes(aiTask)) {
if (aiTask !== 'none') {
const taskPath = path.join(taskDir, `${aiTask}.js`);
if (!fs.existsSync(taskPath)) {
bot.chat(`I dont know how to ${aiTask.replace(/-/g, ' ')} yet, learning now...`);
await generateAndSaveTask(aiTask, config.ai);
}
try {
const task = require(path.join(taskDir, aiTask));
const task = require(taskPath);
setActiveTask(aiTask);
bot.chat(`Okay, Ill try to ${aiTask.replace(/-/g, ' ')}.`);
await task(bot, db, bot.chat);
clearActiveTask();
return;
} catch (err) {
console.error(`[AI TASK ERROR] ${aiTask}:`, err.message);
bot.chat(`Something went wrong trying to do "${aiTask}".`);
console.error(`[TASK ERROR - AI GENERATED] ${aiTask}:`, err.message);
bot.chat(`I tried to learn how to ${aiTask.replace(/-/g, ' ')}, but it didnt work.`);
clearActiveTask();
return;
}