updated logging surroundings
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 25s
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 25s
This commit is contained in:
parent
ce8b24629f
commit
efbe339dbb
1 changed files with 43 additions and 3 deletions
|
|
@ -12,6 +12,8 @@ const INTERESTING_BLOCKS = [
|
|||
'bed', 'beacon', 'portal'
|
||||
];
|
||||
|
||||
const COOLDOWN_MINUTES = 5;
|
||||
|
||||
module.exports = async function logSurroundings() {
|
||||
const bot = getBot();
|
||||
if (!bot) return;
|
||||
|
|
@ -22,6 +24,9 @@ module.exports = async function logSurroundings() {
|
|||
count: 10
|
||||
});
|
||||
|
||||
const now = Date.now();
|
||||
const observedTypes = new Set();
|
||||
|
||||
for (const pos of found) {
|
||||
const block = bot.blockAt(pos);
|
||||
if (!block || !block.name) continue;
|
||||
|
|
@ -29,13 +34,48 @@ module.exports = async function logSurroundings() {
|
|||
const label = `found:${block.name}:${pos.x},${pos.y},${pos.z}`;
|
||||
const memoryData = {
|
||||
name: block.name,
|
||||
position: pos
|
||||
position: pos,
|
||||
timestamp: now
|
||||
};
|
||||
|
||||
// Store this exact block if not seen before
|
||||
db.get(`SELECT id FROM memory WHERE label = ?`, [label], (err, row) => {
|
||||
if (err || row) return;
|
||||
saveMemory(db, label, memoryData);
|
||||
});
|
||||
|
||||
if (!observedTypes.has(block.name)) {
|
||||
observedTypes.add(block.name);
|
||||
|
||||
const typeLabel = `recent:${block.name}`;
|
||||
getMemory(db, typeLabel, (err, memory) => {
|
||||
if (err || !memory) {
|
||||
saveMemory(db, typeLabel, { lastSeen: now });
|
||||
bot.chat(`I noticed ${block.name.replace(/_/g, ' ')} nearby.`);
|
||||
} else {
|
||||
const age = (now - memory.lastSeen) / (1000 * 60); // in minutes
|
||||
if (age > COOLDOWN_MINUTES) {
|
||||
saveMemory(db, typeLabel, { lastSeen: now });
|
||||
bot.chat(`I saw another ${block.name.replace(/_/g, ' ')} nearby.`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (found.length > 0) {
|
||||
bot.chat(`I noticed ${found.length} interesting blocks nearby.`);
|
||||
const summary = found
|
||||
.map(pos => bot.blockAt(pos)?.name)
|
||||
.filter(Boolean)
|
||||
.reduce((acc, name) => {
|
||||
acc[name] = (acc[name] || 0) + 1;
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const summaryMsg = Object.entries(summary)
|
||||
.map(([name, count]) => `${count} ${name.replace(/_/g, ' ')}`)
|
||||
.join(', ');
|
||||
|
||||
bot.chat(`I noticed: ${summaryMsg}`);
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue