From 8263dd5f5642f8ee07a31b264ed8c7f4f21bfeab Mon Sep 17 00:00:00 2001 From: MarcUs7i <96580944+MarcUs7i@users.noreply.github.com> Date: Sun, 23 Feb 2025 00:16:12 +0100 Subject: [PATCH] Changed watcher to only reload after midnight --- watcher.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/watcher.js b/watcher.js index 9f23f78..f1ba126 100644 --- a/watcher.js +++ b/watcher.js @@ -13,6 +13,13 @@ watchFile('./config.js', async ()=>{ // Dynamically reload config and watch it f const statusFile = './static/status.json'; +const getMillisUntilMidnight = () => { + const now = new Date(); + const midnight = new Date(now); + midnight.setHours(24, 0, 0, 0); + return midnight - now; +} + const delay = async t=>new Promise(r=>setTimeout(r, t)); const handlize = s=>s.toLowerCase().replace(/[^a-z0-9]/g, ' ').trim().replace(/\s+/g, '-'); const checkContent = async (content, criterion, negate=false) => { @@ -332,5 +339,5 @@ while(true) { console.error(e); } config.verbose && console.log('✅ Done'); - await delay(config.interval * 60_000 - (Date.now() - startPulse)); + await delay(getMillisUntilMidnight()); } \ No newline at end of file