30 lines
No EOL
838 B
JavaScript
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 }; |