diff --git a/commands/misc/timer.js b/commands/misc/timer.js index c4764f1..bc9a31f 100644 --- a/commands/misc/timer.js +++ b/commands/misc/timer.js @@ -1,3 +1,4 @@ +const parseTime = require('../../util/parseTime'); module.exports = { name: "timer", description: "Set a timer for a time in minutes.", @@ -5,14 +6,13 @@ module.exports = { execute({message, args}) { if(args.length < 2) return message.channel.send("Please specify a time in minutes, and a message to send after the timer has finished"); - let time = parseInt(args[0]); + let time = parseTime(args[0]); if(isNaN(time)) return message.channel.send("Specify a time in number of minutes"); - time = time * 60000; let sendText = args.slice(1).join(" "); setTimeout(function(){ message.channel.send(`<@${message.author.id}>, ${sendText}`); }, time); - message.channel.send(`I will remind you in `); + message.channel.send(`I will remind you `); } }; \ No newline at end of file diff --git a/util/parseTime.js b/util/parseTime.js new file mode 100644 index 0000000..ee23719 --- /dev/null +++ b/util/parseTime.js @@ -0,0 +1,19 @@ +module.exports = function(time){ + let timeInMilliseconds = parseInt(time.slice(0, time.length - 1)) + let letter = time.slice(time.length - 1) + if(!isNaN(letter)) return parseInt(time) * 60000 + switch (letter.toUpperCase()) { + case "H": + timeInMilliseconds = timeInMilliseconds * 3600000; // 3 600 000 + break; + case "M": + timeInMilliseconds = timeInMilliseconds * 60000; // 60 000 + break; + case "S": + timeInMilliseconds = timeInMilliseconds * 1000; // 1 000 + break; + default: + timeInMilliseconds = -1; + } + return timeInMilliseconds; +}