mirror of
https://github.com/reality/dbot.git
synced 2024-11-24 04:49:25 +01:00
Load missing config directives from defaults file
This commit is contained in:
parent
d9f8ff0c1f
commit
af20b5cbfb
25
run.js
25
run.js
@ -5,26 +5,23 @@ var fs = require('fs'),
|
|||||||
require('./snippets');
|
require('./snippets');
|
||||||
|
|
||||||
var DBot = function(timers) {
|
var DBot = function(timers) {
|
||||||
// Load external files
|
// Load config
|
||||||
var requiredConfigKeys = [ 'name', 'servers', 'admins', 'moderators', 'moduleNames', 'language', 'debugMode' ];
|
|
||||||
try {
|
try {
|
||||||
this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log('Config file is screwed up. Attempting to load defaults.');
|
console.log('Config file is invalid. Stopping');
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.config = JSON.parse(fs.readFileSync('config.json.sample', 'utf-8'));
|
var defaultConfig = JSON.parse(fs.readFileSync('config.json.sample', 'utf-8'));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log('Error loading sample config. Bugger off. Stopping.');
|
console.log('Error loading sample config. Bugger off this should not even be edited. Stopping.');
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_.each(requiredConfigKeys, function(key) {
|
// Load missing config directives from sample file
|
||||||
if(!_.has(this.config, key)) {
|
_.defaults(this.config, defaultConfig);
|
||||||
console.log('Error: Please set a value for ' + key + ' in ' +
|
|
||||||
'config.json. Stopping.');
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
var rawDB;
|
var rawDB;
|
||||||
try {
|
try {
|
||||||
@ -172,7 +169,7 @@ DBot.prototype.reloadModules = function() {
|
|||||||
|
|
||||||
this.config[name] = config;
|
this.config[name] = config;
|
||||||
_.each(config.dbKeys, function(dbKey) {
|
_.each(config.dbKeys, function(dbKey) {
|
||||||
if(!_.has(this.db, dbKey( {
|
if(!_.has(this.db, dbKey)) {
|
||||||
this.db[dbKey] = {};
|
this.db[dbKey] = {};
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
Loading…
Reference in New Issue
Block a user