Add option to use timestamp on timer command

This commit is contained in:
SileNce5k 2022-09-05 17:00:48 +02:00
parent 6f7ec05dd0
commit 88d5237680
2 changed files with 6 additions and 3 deletions

View file

@ -5,13 +5,13 @@ module.exports = {
description: "Set a timer for a time in minutes.",
moreHelp: ["Usage:"
,"`<prefix>timer <time_in_minutes> <message_to_send>`"
,"`<prefix>timer <time>(d|h|m|s) <message_to_send>`"
,"`<prefix>timer <time>(d|h|m|s|t) <message_to_send>`"
,"Bot will mention you after the time has passed, with the custom message."],
execute({client, message, args}) {
if(args.length < 2)
return message.channel.send("Please specify a time, and a message to send after the timer has finished");
let currentUnixTime = Math.floor(new Date() / 1000);
let timeInSeconds = parseTime(args[0]);
let timeInSeconds = parseTime(args[0], currentUnixTime);
if(isNaN(timeInSeconds)){
return message.channel.send("Please specify a time, and a message to send after the timer has finished")
}

View file

@ -1,4 +1,4 @@
module.exports = function(time){
module.exports = function(time, currentUnixTime){
let timeInSeconds = parseFloat(time.slice(0, time.length - 1))
let letter = time.slice(time.length - 1)
if(!isNaN(letter)) return parseFloat(time) * 60;
@ -14,6 +14,9 @@ module.exports = function(time){
case "D":
timeInSeconds = timeInSeconds * 86400;
break;
case "T": // TODO: Make it so that I can have multiple letters per case, so that "TS" would work here.
timeInSeconds = timeInSeconds - currentUnixTime;
break;
default:
timeInSeconds = NaN;
}