Compare commits
No commits in common. "f14eff3f9ce88615deafc63062ac24b6bee7977f" and "c74f323c1b4d1e89ec17d088e13cdfd9a1efb903" have entirely different histories.
f14eff3f9c
...
c74f323c1b
5 changed files with 27 additions and 48 deletions
|
@ -4,11 +4,11 @@ const parseTime = require('../../util/timer/parseTime');
|
|||
const showTimer = require('../../util/timer/showTimer');
|
||||
module.exports = {
|
||||
name: "timer",
|
||||
description: "Set a timer for a date or time duration.",
|
||||
description: "Set a timer for a time in minutes.",
|
||||
moreHelp: ["Usage:"
|
||||
,"`<prefix>timer [add|create] <time_in_minutes> <message_to_send>`"
|
||||
,"`<prefix>timer <time>(d|h|m|s|t) <message_to_send>`"
|
||||
,"`<prefix>timer <future_date> <message_to_send>`"
|
||||
,"`<prefix>timer <time_in_minutes> <message_to_send>`"
|
||||
,"`<prefix>timer edit <timer_id> <new_time_in_minutes> <new_message_to_send>` (not implemented)"
|
||||
,"`<prefix>timer [delete|remove] <timer_id>`"
|
||||
,"`<prefix>timer show <timer_id>`"
|
||||
|
@ -18,8 +18,7 @@ module.exports = {
|
|||
switch (args[0]) {
|
||||
case "add":
|
||||
case "create":
|
||||
args.shift()
|
||||
sendText = await createTimer(message, args);
|
||||
sendText = await createTimer(message, args, false);
|
||||
break;
|
||||
case "edit":
|
||||
sendText = "not implemented yet"
|
||||
|
@ -38,8 +37,8 @@ module.exports = {
|
|||
sendText = "Please specify a time, and a message to send after the timer has finished";
|
||||
break;
|
||||
}
|
||||
if(!isNaN(parseTime(args[0], Math.floor(new Date() / 1000))) || !isNaN(Date.parse(args[0])))
|
||||
sendText = await createTimer(message, args);
|
||||
if(!isNaN(parseTime(args[0], Math.floor(new Date() / 1000))))
|
||||
sendText = await createTimer(message, args, true);
|
||||
break;
|
||||
}
|
||||
message.channel.send(sendText);
|
||||
|
|
|
@ -48,7 +48,6 @@ client.whitelist = {
|
|||
guild: new Collection(),
|
||||
user: new Collection()
|
||||
}
|
||||
process.env.TZ = "UTC";
|
||||
|
||||
createAndLoadWhitelistTable(client.whitelist);
|
||||
|
||||
|
|
|
@ -1,26 +1,17 @@
|
|||
const fs = require('fs');
|
||||
const parseTime = require('./parseTime');
|
||||
const timeUntil = require('./timeUntil');
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
module.exports = async function (message, args) {
|
||||
module.exports = async function (message, args, compatibility) {
|
||||
const databasePath = 'data/database.db'
|
||||
if (args.length < 2)
|
||||
return "Please specify a time, and a message to send after the timer has finished";
|
||||
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;
|
||||
if(!isNaN(Date.parse(args[0])) && isNaN(parseTime(args[0], currentUnixTime))){
|
||||
timeInSeconds = timeUntil(args[0]).totalInSeconds;
|
||||
if(timeInSeconds < 0){
|
||||
return "The date must not be in the past."
|
||||
}
|
||||
}else {
|
||||
timeInSeconds = parseTime(args[0], currentUnixTime);
|
||||
}
|
||||
let timeInSeconds = compatibility ? parseTime(args[0], currentUnixTime) : parseTime(args[1], currentUnixTime);
|
||||
if (isNaN(timeInSeconds)) {
|
||||
return "Please specify a time, and a message to send after the timer has finished"
|
||||
return message.channel.send("Please specify a time, and a message to send after the timer has finished")
|
||||
}
|
||||
const customMessage = args.slice(1).join(" ")
|
||||
const reminderTime = currentUnixTime + timeInSeconds
|
||||
let customMessage = compatibility ? args.slice(1).join(" ") : args.slice(2).join(" ");
|
||||
let reminderTime = currentUnixTime + timeInSeconds
|
||||
let newTimerID;
|
||||
const db = new sqlite3.Database(databasePath)
|
||||
let sendText = await new Promise((resolve, reject)=>{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module.exports = function(time, currentUnixTime){
|
||||
let timeInSeconds = parseFloat(time)
|
||||
const letterCount = time.length - timeInSeconds.toString().length;
|
||||
const letter = time.slice(time.length - letterCount);
|
||||
let timeInSeconds = parseFloat(time.slice(0, time.length - 1))
|
||||
let letter = time.slice(time.length - 1)
|
||||
if(!isNaN(letter)) return parseFloat(time) * 60;
|
||||
switch (letter.toUpperCase()) {
|
||||
case "H":
|
||||
timeInSeconds = timeInSeconds * 3_600;
|
||||
|
@ -14,8 +14,7 @@ module.exports = function(time, currentUnixTime){
|
|||
case "D":
|
||||
timeInSeconds = timeInSeconds * 86_400;
|
||||
break;
|
||||
case "TS": // Unix timestamp
|
||||
case "T":
|
||||
case "T": // TODO: Make it so that I can have multiple letters per case, so that "TS" would work here.
|
||||
timeInSeconds = timeInSeconds - currentUnixTime;
|
||||
break;
|
||||
case "W":
|
||||
|
@ -23,6 +22,17 @@ module.exports = function(time, currentUnixTime){
|
|||
break;
|
||||
default:
|
||||
timeInSeconds = NaN;
|
||||
if(time.includes(':'))
|
||||
timeInSeconds = getTime(time, currentUnixTime);
|
||||
}
|
||||
return timeInSeconds;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getTime(time, currentUnixTime) {
|
||||
|
||||
|
||||
|
||||
return timeInSeconds;
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
module.exports = function(targetTime) {
|
||||
const countDownDate = new Date(targetTime).getTime();
|
||||
const now = new Date().getTime();
|
||||
|
||||
const distance = countDownDate - now;
|
||||
let days = Math.floor(distance / (1000 * 60 * 60 * 24));
|
||||
let hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
||||
let minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
|
||||
let seconds = Math.floor((distance % (1000 * 60)) / 1000);
|
||||
|
||||
if (seconds < 0) { // Due to how the math above works, if the input time is in the past, the time will be off by 1.
|
||||
days = days + 1;
|
||||
hours = hours + 1;
|
||||
minutes = minutes + 1;
|
||||
seconds = seconds + 1;
|
||||
}
|
||||
|
||||
const totalInSeconds = (days * 24 * 60 * 60) + (hours * 60 * 60) + (minutes * 60) + seconds;
|
||||
return { days, hours, minutes, seconds, totalInSeconds };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue