diff --git a/commands/misc/timers.js b/commands/misc/timers.js index eb44bed..9917dfe 100644 --- a/commands/misc/timers.js +++ b/commands/misc/timers.js @@ -1,13 +1,33 @@ +const sqlite3 = require('sqlite3').verbose(); module.exports = { name: "timers", - description: "Check your own timers", - execute({client, message}) { + description: "List all your timers.", + async execute({message}) { let authorTimers = ""; - client.timers.forEach(timer => { - if(timer.user === message.author.id) - authorTimers += `${timer.ID} : `; + let sendText = ""; + + const db = new sqlite3.Database('data/database.db'); + await new Promise((resolve, reject) => { + db.all(`SELECT * FROM timers WHERE user = ? AND hasPassed = ?`, [message.author.id, false], function (error, timers){ + if(error){ + console.error("Error while trying to read timer from database: ", error) + sendText = "An error occured while trying to read timer from database. Check console."; + reject(error); + }else{ + timers.forEach(timer => { + if(timer.user === message.author.id) + authorTimers += `${timer.ID} : \n`; + }); + if(authorTimers === ""){ + sendText = "You have no timers set."; + }else if(sendText === ""){ + sendText = `Your timers:\n${authorTimers}`; + } + resolve(); + } + }); + }); - let sendText = "" === authorTimers ? `You have no timers` : `Your timers are:\n${authorTimers}` message.channel.send(sendText); } }; \ No newline at end of file