Vesion 0.1.0 - Initial Version with First Commands
This commit is contained in:
66
src/main.js
Normal file
66
src/main.js
Normal file
@@ -0,0 +1,66 @@
|
||||
const fs = require("node:fs")
|
||||
const path = require("path")
|
||||
const { LogType } = require("./modules/sub-log")
|
||||
const { DiscordBot } = require("./modules/discord-bot")
|
||||
const { __glob } = require("./modules/global-variables")
|
||||
|
||||
setup()
|
||||
|
||||
function setup() {
|
||||
|
||||
//Log - INIT PHASE
|
||||
|
||||
const dlog = new LogType("Discord")
|
||||
const wlog = new LogType("Web")
|
||||
const alog = new LogType("Authentification")
|
||||
|
||||
// Discord Bot - INIT PHASE
|
||||
|
||||
const bot = new DiscordBot(getConfig(dlog), dlog)
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Config GETTER
|
||||
|
||||
function getConfig(dlog) {
|
||||
|
||||
dlog.step.init("getConfig", "Récupération du fichier de configuration")
|
||||
|
||||
if(fs.existsSync(__glob.CONFIG)) {
|
||||
try {
|
||||
|
||||
var config_data = JSON.parse(fs.readFileSync(__glob.CONFIG))
|
||||
|
||||
dlog.log("Fichier de configuration trouvé : TOKEN : " + config_data.token)
|
||||
dlog.step.end("getConfig")
|
||||
|
||||
return config_data
|
||||
} catch(error) {
|
||||
dlog.step.error("getConfig", error)
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
dlog.warn("Fichier de configuration introuvable !")
|
||||
|
||||
try {
|
||||
var new_config = {
|
||||
"token":"",
|
||||
"guild_id":"",
|
||||
"voice_channel_id":""
|
||||
}
|
||||
|
||||
|
||||
fs.writeFileSync(__glob.CONFIG, JSON.stringify(new_config, null, 2))
|
||||
dlog.log("Création d'un fichier de configuration ! Redémarrage de l'application nécéssaire !")
|
||||
dlog.step.error("getConfig", "Redémarrage requis pour lire la nouvelle configuration !")
|
||||
process.exit(0)
|
||||
} catch(error) {
|
||||
dlog.step.error("getConfig", "Tentative de création du fichier de configuration échoué !" + error)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user