Rewrite timer command to use JSON
* Rewrite parseTime to use seconds instead of ms * Move parseTime to timer subdirectory * Implement checkTimer and sendTimerReminder.
This commit is contained in:
parent
a4b75b0161
commit
04f39582a4
7 changed files with 55 additions and 14 deletions
11
util/timer/checkTimer.js
Normal file
11
util/timer/checkTimer.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const checkTimer = require('./checkTimer')
|
||||
const sendTimerReminder = require('./sendTimerReminder')
|
||||
module.exports = function (client) {
|
||||
client.timers.forEach(timer => {
|
||||
if(parseInt(timer.reminderDate) >= Math.floor(new Date() / 1000)){
|
||||
sendTimerReminder(client, timer);
|
||||
client.timers.pop(timer);
|
||||
}
|
||||
});
|
||||
setTimeout(checkTimer, 1000, client);
|
||||
}
|
19
util/timer/parseTime.js
Normal file
19
util/timer/parseTime.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
module.exports = function(time){
|
||||
let timeInSeconds = parseInt(time.slice(0, time.length - 1))
|
||||
let letter = time.slice(time.length - 1)
|
||||
if(!isNaN(letter)) return parseInt(time) * 60;
|
||||
switch (letter.toUpperCase()) {
|
||||
case "H":
|
||||
timeInSeconds = timeInSeconds * 3600; // 3 600 000
|
||||
break;
|
||||
case "M":
|
||||
timeInSeconds = timeInSeconds * 60; // 60 000
|
||||
break;
|
||||
case "S":
|
||||
timeInSeconds = timeInSeconds; // 1 000
|
||||
break;
|
||||
default:
|
||||
timeInSeconds = -1;
|
||||
}
|
||||
return timeInSeconds;
|
||||
}
|
3
util/timer/sendTimerReminder.js
Normal file
3
util/timer/sendTimerReminder.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (client, timer) {
|
||||
client.channels.cache.get(timer.channel).send(`<@${timer.user}>, ${timer.customMessage}`);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue