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:
parent
4d87294196
commit
4ab84dd6d4
1 changed files with 7 additions and 5 deletions
|
@ -2,12 +2,14 @@ const sendTimerReminder = require('./sendTimerReminder')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
module.exports = function (client) {
|
module.exports = function (client) {
|
||||||
const checkTimer = require('./checkTimer')
|
const checkTimer = require('./checkTimer')
|
||||||
client.timers.forEach(timer => {
|
|
||||||
if(parseInt(timer.reminderDate) <= Math.floor(new Date() / 1000)){
|
for(let i = 0; i < client.timers.length; i++){
|
||||||
sendTimerReminder(client, timer);
|
if(parseInt(client.timers[i].reminderDate) <= Math.floor(new Date() / 1000)){
|
||||||
client.timers.pop(timer);
|
sendTimerReminder(client, client.timers[i]);
|
||||||
|
client.timers.splice(i, 1);
|
||||||
|
i--
|
||||||
fs.writeFileSync('data/timers.json', JSON.stringify(client.timers, null, 4))
|
fs.writeFileSync('data/timers.json', JSON.stringify(client.timers, null, 4))
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
setTimeout(checkTimer, 1000, client);
|
setTimeout(checkTimer, 1000, client);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue