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.
This commit is contained in:
SileNce5k 2022-07-01 00:32:55 +02:00
parent 4d87294196
commit 4ab84dd6d4
No known key found for this signature in database
GPG key ID: C507260E7F2583AD

View file

@ -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);
}