Configuration working

This commit is contained in:
plane000
2018-10-16 19:38:13 +01:00
parent a92750d1df
commit bc94c2900b
5 changed files with 41 additions and 2 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
config/
node_modules/
*.log

View File

@@ -1 +0,0 @@
[SYSTEM STARTING UP]

34
src/config.js Normal file
View File

@@ -0,0 +1,34 @@
const Logger = require('../logger');
const fs = require('fs');
module.exports = class Config {
constructor(path) {
this.path = path;
this.Config = {
token: 'YOUR TOKEN HERE'
};
}
load() {
Logger.info('Loading config');
if (fs.existsSync(this.path)) {
try {
this.Config = JSON.parse(fs.readFileSync(this.path));
if (!this.Config.token);
Logger.info('Config loaded successfully');
} catch (e) {
Logger.panic(`Failed to load config... Invalid JSON: ${e}`);
}
} else {
try {
Logger.error('No config found');
fs.writeFileSync(this.path, JSON.stringify(this.Config, null, 4));
Logger.warn(`Created config at: ${this.path}`);
Logger.panic('Config required to be complete');
} catch (e) {
Logger.panic(`Could not create config: ${e}`);
}
}
}
}

View File

@@ -1,5 +1,5 @@
const Logger = require('./logger');
const Config = require('./config');
const Config = require('./config/config');
const Discord = require('discord.js');
const client = new Discord.Client();

View File

@@ -2,6 +2,7 @@ const colours = require('colors/safe');
const fs = require('fs');
let LogLevel = 1;
let Dialect = 'SQLITE';
let logPath = 'logs.log';
module.exports = class Logger {
@@ -18,6 +19,10 @@ module.exports = class Logger {
LogLevel = level;
}
static SetDialect(dialect) {
Dialect = dialect;
}
static get VERBOSE_LOGS() {return 0;}
static get DEBUG_LOGS() {return 1;}
static get INFO_LOGS() {return 2;}