Use an sqlite3 database for timer feature

There were some other small edits as well, mostly formatting or better
logging in certain functions
This commit is contained in:
SileNce5k 2023-05-27 22:16:43 +02:00
parent a098ab6616
commit d41b28ec91
No known key found for this signature in database
GPG key ID: 961132EB78C8915F
13 changed files with 2277 additions and 59 deletions

View file

@ -1,22 +1,24 @@
const createTimer = require('../../util/timer/createTimer');
const deleteTimer = require('../../util/timer/deleteTimer');
const parseTime = require('../../util/timer/parseTime');
const fs = require('fs');
const showTimer = require('../../util/timer/showTimer');
module.exports = {
name: "timer",
description: "Set a timer for a time in minutes.",
moreHelp: ["Usage:"
,"`<prefix>timer <time_in_minutes> <message_to_send>`"
,"`<prefix>timer [add|create] <time_in_minutes> <message_to_send>`"
,"`<prefix>timer <time>(d|h|m|s|t) <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>`"
,"Bot will mention you after the time has passed, with the custom message."],
execute({client, message, args}) {
async execute({message, args}) {
let sendText = "This should never happen.";
switch (args[0]) {
case "add":
case "create":
sendText = createTimer(client, message, args, false);
sendText = await createTimer(message, args, false);
break;
case "edit":
sendText = "not implemented yet"
@ -24,14 +26,15 @@ module.exports = {
case "delete":
case "remove":
let timerID = args[1];
sendText = deleteTimer(client, message.author.id, timerID);
sendText = await deleteTimer(message.author.id, timerID);
break;
case "show":
sendText = showTimer(client, message.author.id, args[1]);
sendText = await showTimer(message.author.id, args[1]);
default:
sendText = "not sure what you mean"
if(!isNaN(parseTime(args[0], Math.floor(new Date() / 1000))))
sendText = createTimer(client, message, args, true);
sendText = await createTimer(message, args, true);
console.log("sendText: ", sendText)
break;
}
message.channel.send(sendText);

View file

@ -5,7 +5,7 @@ module.exports = {
let authorTimers = "";
client.timers.forEach(timer => {
if(timer.user === message.author.id)
authorTimers += `${timer.ID} : <t:${timer.reminderDate}:R> | ${timer.customMessage}\n`;
authorTimers += `${timer.ID} : <t:${timer.reminderDate}:R>`;
});
let sendText = "" === authorTimers ? `You have no timers` : `Your timers are:\n${authorTimers}`
message.channel.send(sendText);