From 4ab84dd6d4743993dc336f7dda142f92a14ec183 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Fri, 1 Jul 2022 00:32:55 +0200 Subject: [PATCH] Fix timer being sent multiple times I used array.pop instead of array.splice for some reason. I thought it would work, but I guess I didn't read MDN thoroughly enough when I first implemented this function. --- util/timer/checkTimer.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/util/timer/checkTimer.js b/util/timer/checkTimer.js index a38bc65..557e4bf 100644 --- a/util/timer/checkTimer.js +++ b/util/timer/checkTimer.js @@ -2,12 +2,14 @@ const sendTimerReminder = require('./sendTimerReminder') const fs = require('fs') module.exports = function (client) { const checkTimer = require('./checkTimer') - client.timers.forEach(timer => { - if(parseInt(timer.reminderDate) <= Math.floor(new Date() / 1000)){ - sendTimerReminder(client, timer); - client.timers.pop(timer); + + for(let i = 0; i < client.timers.length; i++){ + if(parseInt(client.timers[i].reminderDate) <= Math.floor(new Date() / 1000)){ + sendTimerReminder(client, client.timers[i]); + client.timers.splice(i, 1); + i-- fs.writeFileSync('data/timers.json', JSON.stringify(client.timers, null, 4)) } - }); + } setTimeout(checkTimer, 1000, client); }