Add convertion of custom commands
All checks were successful
CI / CI (push) Successful in 22s
Lint Codebase / eslint (push) Successful in 15s

This commit is contained in:
SileNce5k 2024-12-17 10:39:30 +01:00
parent 904fa25a6d
commit 3c8bec050d
Signed by: SileNce
GPG key ID: B0A142BB4291B204
2 changed files with 52 additions and 0 deletions

View file

@ -2,6 +2,7 @@ const fs = require('fs');
const createInitialConfig = require("./util/createInitialConfig") const createInitialConfig = require("./util/createInitialConfig")
const convertTimerJSONToSQL = require('./util/timer/convertTimerJSONToSQL.js'); const convertTimerJSONToSQL = require('./util/timer/convertTimerJSONToSQL.js');
const createTimersTable = require('./server/createDatabaseTables/createTimersTable'); const createTimersTable = require('./server/createDatabaseTables/createTimersTable');
const convertCustomCommandsJSONToSQL = require('./server/convertCustomCommandsJSONToSQL.js');
if(!fs.existsSync("./data/config.json")) { if(!fs.existsSync("./data/config.json")) {
createInitialConfig(); createInitialConfig();
} }
@ -10,11 +11,22 @@ async function checkAndConvertJSONToSQL(){
if(fs.existsSync("./data/timers.json")){ if(fs.existsSync("./data/timers.json")){
process.stdout.write(true + "\n") process.stdout.write(true + "\n")
await convertTimerJSONToSQL(); await convertTimerJSONToSQL();
fs.renameSync('data/timers.json', 'data/timers.json.old'); fs.renameSync('data/timers.json', 'data/timers.json.old');
console.log("Renamed timers.json to timers.json.old"); console.log("Renamed timers.json to timers.json.old");
}else{ }else{
process.stdout.write(false + "\n") process.stdout.write(false + "\n")
} }
process.stdout.write("Checking if customCommands.json exists... ")
if(fs.existsSync('./data/customCommands.json')){
process.stdout.write(true + "\n")
await convertCustomCommandsJSONToSQL();
fs.renameSync('data/customCommands.json', 'data/customCommands.json.old');
}else{
process.stdout.write(false + "\n")
}
} }

View file

@ -0,0 +1,40 @@
const sqlite3 = require('sqlite3').verbose();
module.exports = async function () {
const customCommands = require('../data/customCommands.json')
const db = new sqlite3.Database('data/database.db');
return new Promise((resolve, reject) => {
customCommands.forEach(element => {
});
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();
})
}