cletus/bot/memory/signs.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

30 lines
No EOL
838 B
JavaScript

// memory/signs.js
const { saveMemory, getMemory, listMemory } = require('./index');
function logSign(db, text, position) {
const label = `sign:${text.toLowerCase().replace(/\s+/g, '_').slice(0, 50)}`;
saveMemory(db, label, {
text,
position,
timestamp: Date.now()
});
}
function getAllSigns(db, callback) {
listMemory(db, (err, entries) => {
if (err) return callback(err, []);
const signs = entries.filter(e => e.label.startsWith('sign:'));
callback(null, signs);
});
}
function findSignContaining(db, keyword, callback) {
getAllSigns(db, (err, signs) => {
if (err) return callback(err, null);
const match = signs.find(s => s.data.text.toLowerCase().includes(keyword.toLowerCase()));
callback(null, match || null);
});
}
module.exports = { logSign, getAllSigns, findSignContaining };