From efbe339dbb55e7362dbdae1c837f4f8bcac9dc98 Mon Sep 17 00:00:00 2001 From: roberts Date: Sat, 10 May 2025 19:08:16 -0500 Subject: [PATCH] updated logging surroundings --- bot/lib/log-surroundings.js | 46 ++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/bot/lib/log-surroundings.js b/bot/lib/log-surroundings.js index 97d1582..446bb6d 100644 --- a/bot/lib/log-surroundings.js +++ b/bot/lib/log-surroundings.js @@ -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 }; - saveMemory(db, label, memoryData); + // 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}`); } }; \ No newline at end of file