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:
parent
a098ab6616
commit
d41b28ec91
13 changed files with 2277 additions and 59 deletions
22
server.js
22
server.js
|
@ -1,11 +1,23 @@
|
|||
const fs = require('fs');
|
||||
const createInitialConfig = require("./util/createInitialConfig")
|
||||
const convertJSONToSQL = require('./util/timer/convertJSONToSQL');
|
||||
if(!fs.existsSync("./data/config.json")) {
|
||||
createInitialConfig();
|
||||
}
|
||||
if(!fs.existsSync("./data/timers.json")){
|
||||
fs.writeFileSync('./data/timers.json', "[]");
|
||||
async function checkAndConvertJSONToSQL(){
|
||||
process.stdout.write("Checking if timers.json exists... ")
|
||||
if(fs.existsSync("./data/timers.json")){
|
||||
process.stdout.write(true + "\n")
|
||||
await createDatabaseTables();
|
||||
await convertJSONToSQL();
|
||||
fs.renameSync('data/timers.json', 'data/timers.json.old');
|
||||
console.log("Renamed timers.json to timers.json.old");
|
||||
}else{
|
||||
process.stdout.write(false + "\n")
|
||||
}
|
||||
}
|
||||
const createDatabaseTables = require('./server/createDatabaseTables');
|
||||
checkAndConvertJSONToSQL();
|
||||
const Discord = require('discord.js');
|
||||
const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.GUILD_PRESENCES] });
|
||||
const {
|
||||
|
@ -23,12 +35,7 @@ client.settings = new Discord.Collection();
|
|||
client.commands = new Discord.Collection();
|
||||
client.serverPrefixes = new Discord.Collection();
|
||||
client.netmodules = new Discord.Collection();
|
||||
client.timers = require('./data/timers.json');
|
||||
|
||||
if(!fs.existsSync("./data/lastTimerID.txt")){
|
||||
fs.writeFileSync('./data/lastTimerID.txt', "0");
|
||||
}
|
||||
client.lastTimerID = parseInt(fs.readFileSync('./data/lastTimerID.txt', 'utf8'));
|
||||
|
||||
client.settings.set("presenceType", presenceType);
|
||||
client.settings.set("presenceText", presenceText);
|
||||
|
@ -37,6 +44,7 @@ const reloadCommands = require("./util/reloadCommands.js");
|
|||
const reloadNetModules = require('./util/reloadNetModules');
|
||||
const onMessage = require('./server/message');
|
||||
const onReady = require('./server/ready');
|
||||
|
||||
reloadCommands(client)
|
||||
reloadNetModules(client)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue