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:
SileNce5k 2022-06-08 16:29:13 +02:00
parent a4b75b0161
commit 04f39582a4
No known key found for this signature in database
GPG key ID: C507260E7F2583AD
7 changed files with 55 additions and 14 deletions

11
util/timer/checkTimer.js Normal file
View 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
View 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;
}

View file

@ -0,0 +1,3 @@
module.exports = function (client, timer) {
client.channels.cache.get(timer.channel).send(`<@${timer.user}>, ${timer.customMessage}`);
}