forked from GitHub/dbot
file existence checking for module property files and config.json [#163]
This commit is contained in:
parent
2e620fea6f
commit
6f73fde865
@ -1 +1 @@
|
|||||||
Subproject commit 42ce44222f4ef4311cae5648438b872227c9b3bf
|
Subproject commit 33886df41d84c160270b581f072e710e4c9d00e8
|
34
run.js
34
run.js
@ -5,7 +5,9 @@ var fs = require('fs'),
|
|||||||
require('./snippets');
|
require('./snippets');
|
||||||
|
|
||||||
var DBot = function(timers) {
|
var DBot = function(timers) {
|
||||||
// Load DB
|
|
||||||
|
/*** Load the DB ***/
|
||||||
|
|
||||||
if(fs.existsSync('db.json')) {
|
if(fs.existsSync('db.json')) {
|
||||||
try {
|
try {
|
||||||
this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
||||||
@ -21,12 +23,18 @@ var DBot = function(timers) {
|
|||||||
this.db.config = {};
|
this.db.config = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load config
|
/*** Load the Config ***/
|
||||||
|
|
||||||
|
if(!fs.existsSync('config.json')) {
|
||||||
|
console.log('Error: config.json file does not exist. Stopping');
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
this.config = _.clone(this.db.config);
|
this.config = _.clone(this.db.config);
|
||||||
try {
|
try {
|
||||||
_.defaults(this.config, JSON.parse(fs.readFileSync('config.json', 'utf-8')));
|
_.defaults(this.config, JSON.parse(fs.readFileSync('config.json', 'utf-8')));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log('Config file is invalid. Stopping');
|
console.log('Config file is invalid. Stopping: ' + err);
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +48,8 @@ var DBot = function(timers) {
|
|||||||
// Load missing config directives from sample file
|
// Load missing config directives from sample file
|
||||||
_.defaults(this.config, defaultConfig);
|
_.defaults(this.config, defaultConfig);
|
||||||
|
|
||||||
// Load Strings file
|
/*** Load main strings ***/
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));
|
this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
@ -216,13 +225,16 @@ DBot.prototype.reloadModules = function() {
|
|||||||
// Load the module data
|
// Load the module data
|
||||||
_.each([ 'commands', 'pages', 'api' ], function(property) {
|
_.each([ 'commands', 'pages', 'api' ], function(property) {
|
||||||
var propertyObj = {};
|
var propertyObj = {};
|
||||||
try {
|
|
||||||
var propertyKey = require.resolve(moduleDir + property);
|
if(fs.existsSync(moduleDir + property + '.js')) {
|
||||||
if(propertyKey) delete require.cache[propertyKey];
|
try {
|
||||||
propertyObj = require(moduleDir + property).fetch(this);
|
var propertyKey = require.resolve(moduleDir + property);
|
||||||
} catch(err) {
|
if(propertyKey) delete require.cache[propertyKey];
|
||||||
console.log('Module error (' + module.name + ') in ' + property + ': ' + err);
|
propertyObj = require(moduleDir + property).fetch(this);
|
||||||
}
|
} catch(err) {
|
||||||
|
console.log('Module error (' + module.name + ') in ' + property + ': ' + err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!_.has(module, property)) module[property] = {};
|
if(!_.has(module, property)) module[property] = {};
|
||||||
_.extend(module[property], propertyObj);
|
_.extend(module[property], propertyObj);
|
||||||
|
Loading…
Reference in New Issue
Block a user