cletus/bot/states/ReadFromSign.js
roberts 2a9f9159bd
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 26s
Massive Overhaul. Added state machine.
2025-05-10 12:24:59 -05:00

38 lines
1.1 KiB
JavaScript

// states/readFromSign.js
const { getBot } = require('../core/context');
const { chatWithAI } = require('../lib/ai-helper');
const { setSafeZone } = require('../memory/locations');
const config = require('../config.json');
const db = require('../db');
module.exports = async function ReadFromSign() {
const bot = getBot();
console.log('[STATE] ReadFromSign');
const signs = bot.findBlocks({
matching: block => block.name.includes('sign'),
maxDistance: 10,
count: 5
});
for (const pos of signs) {
try {
const text = await bot.readSign(pos);
const keywords = config.safeZone.keywords;
const matchedKeyword = keywords.find(k => text.toLowerCase().includes(k));
if (matchedKeyword) {
const standardizedLabel = matchedKeyword.toLowerCase();
setSafeZone(db, standardizedLabel, pos);
bot.chat(`You set a safe zone for "${standardizedLabel}".`);
}
const response = await chatWithAI(`You read a sign that says: "${text}". What should you do?`, config.ai);
bot.chat(response);
break;
} catch (err) {
console.warn('[SIGN] Read failed:', err.message);
}
}
};