Rewrite timers.js to use database
This commit is contained in:
parent
b0e9f88879
commit
fecd6877ea
1 changed files with 26 additions and 6 deletions
|
@ -1,13 +1,33 @@
|
||||||
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "timers",
|
name: "timers",
|
||||||
description: "Check your own timers",
|
description: "List all your timers.",
|
||||||
execute({client, message}) {
|
async execute({message}) {
|
||||||
let authorTimers = "";
|
let authorTimers = "";
|
||||||
client.timers.forEach(timer => {
|
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)
|
if(timer.user === message.author.id)
|
||||||
authorTimers += `${timer.ID} : <t:${timer.reminderDate}:R>`;
|
authorTimers += `${timer.ID} : <t:${timer.reminderTime.toFixed(0)}:R>\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);
|
message.channel.send(sendText);
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue