Check for required keys in config

This commit is contained in:
Luke Slater 2012-12-12 18:33:29 +00:00
parent a431d4c636
commit 918a3c4540

8
run.js
View File

@ -5,6 +5,7 @@ require('./snippets');
var DBot = function(timers) { var DBot = function(timers) {
// Load external files // Load external files
var requiredConfigKeys = [ 'name', 'servers', 'admin', 'moduleNames', 'language' ];
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) {
@ -16,6 +17,13 @@ var DBot = function(timers) {
process.exit(); process.exit();
} }
} }
requiredConfigKeys.each(function(key) {
if(!this.config.hasOwnProperty(key)) {
console.log('Error: Please set a value for ' + key + ' in ' +
'config.json. Stopping.');
process.exit();
}
}.bind(this));
var rawDB; var rawDB;
try { try {