Updated Idle and HandleChat.
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 26s

This commit is contained in:
roberts 2025-05-10 19:28:56 -05:00
parent eba4ab70c8
commit d8a907dc63
2 changed files with 32 additions and 9 deletions

View file

@ -26,8 +26,11 @@ module.exports = async function HandleChat() {
if (matchedTask) {
try {
const task = require(path.join(taskDir, matchedTask));
const { setActiveTask, clearActiveTask } = require('../core/context');
setActiveTask(matchedTask);
bot.chat(`Okay, Ill try to ${matchedTask.replace(/-/g, ' ')}.`);
await task();
await task(bot, db, bot.chat);
clearActiveTask();
return;
} catch (err) {
console.error(`[TASK ERROR] ${matchedTask}:`, err.message);
@ -35,6 +38,23 @@ module.exports = async function HandleChat() {
}
}
const response = await chatWithAI(message, config.ai);
bot.chat(response);
if (!matchedTask) {
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 aiResponse = await chatWithAI(prompt, config.ai);
const aiTask = aiResponse.trim().toLowerCase().replace(/\s+/g, '-');
if (availableTasks.includes(aiTask)) {
const task = require(path.join(taskDir, aiTask));
bot.chat(`Okay, Ill try to ${aiTask.replace(/-/g, ' ')}.`);
setActiveTask(aiTask);
await task(bot, db, bot.chat);
clearActiveTask();
return;
}
}
if (msg.includes(bot.username.toLowerCase())) {
const response = await chatWithAI(message, config.ai);
bot.chat(response);
}
};

View file

@ -1,6 +1,8 @@
// states/Idle.js
const { getBot, getActiveTask, isCombatLocked, getStateMachine } = require('../core/context');
const context = require('../core/context');
const { chatWithAI } = require('../lib/ai-helper');
const config = require('../config.json');
const { GoalNear } = require('mineflayer-pathfinder').goals;
const { getHomeZone } = require('../memory/locations');
const db = require('../db');
@ -43,11 +45,12 @@ module.exports = async function Idle() {
const bounds = zone?.bounds || fallbackBounds;
const safeRadius = Math.min(bounds.x, bounds.z);
const actionRoll = Math.floor(Math.random() * 3);
const prompt = `You're in a safe zone. What would be a useful task to do right now? Your options are: cut grass, tend crops, patrol for mobs.`;
const response = await chatWithAI(prompt, config.ai);
// Randomize an action to do things around the home area.
if (actionRoll === 0) {
if (response.includes('grass')) {
const grass = bot.findBlock({
matching: block => block.name === 'tall_grass',
maxDistance: safeRadius
@ -63,7 +66,7 @@ module.exports = async function Idle() {
}
// manage a farm by harvesting crops.
} else if (actionRoll === 1) {
} else if (response.includes('crop') || response.includes('farm')) {
const crops = bot.findBlocks({
matching: block => ['wheat', 'carrots', 'potatoes'].includes(block.name),
maxDistance: safeRadius,
@ -84,7 +87,7 @@ module.exports = async function Idle() {
}
// Find and attack mobs.
} else {
} else if (response.includes('mob') || response.includes('patrol')) {
const mob = Object.values(bot.entities).find(e =>
e.type === 'mob' &&