Configuration working
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
config/
|
||||
node_modules/
|
||||
*.log
|
||||
|
||||
34
src/config.js
Normal file
34
src/config.js
Normal 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}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;}
|
||||
|
||||
Reference in New Issue
Block a user