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

@ -0,0 +1,33 @@
const fs = require('fs');
const sqlite3 = require('sqlite3').verbose();
module.exports = async function () {
const timers = require('../../data/timers.json')
const db = new sqlite3.Database('data/database.db');
return new Promise((resolve, reject) => {
for (let i = 0; i < timers.length; i++) {
let user = timers[i].user;
let reminderTime = timers[i].reminderDate;
let channel = timers[i].channel;
let customMessage = timers[i].customMessage;
let hasPassed = false;
db.run(`INSERT INTO timers (
user,
reminderTime,
channel,
customMessage,
hasPassed
) VALUES (?, ?, ?, ?, ?)`, [user, reminderTime, channel, customMessage, hasPassed], function (error) {
if (error) {
console.error(`Error while converting timers.json to SQL: ${error}`)
reject(error);
}
})
}
db.close();
console.log("Converted timers.json to SQL successfully.");
resolve();
})
}