38 lines
1.1 KiB
JavaScript
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);
|
|
}
|
|
}
|
|
};
|