mirror of
https://github.com/reality/dbot.git
synced 2024-12-24 11:42:36 +01:00
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
|
20
run.js
20
run.js
@ -5,7 +5,9 @@ var fs = require('fs'),
|
||||
require('./snippets');
|
||||
|
||||
var DBot = function(timers) {
|
||||
// Load DB
|
||||
|
||||
/*** Load the DB ***/
|
||||
|
||||
if(fs.existsSync('db.json')) {
|
||||
try {
|
||||
this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
||||
@ -21,12 +23,18 @@ var DBot = function(timers) {
|
||||
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);
|
||||
try {
|
||||
_.defaults(this.config, JSON.parse(fs.readFileSync('config.json', 'utf-8')));
|
||||
} catch(err) {
|
||||
console.log('Config file is invalid. Stopping');
|
||||
console.log('Config file is invalid. Stopping: ' + err);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
@ -40,7 +48,8 @@ var DBot = function(timers) {
|
||||
// Load missing config directives from sample file
|
||||
_.defaults(this.config, defaultConfig);
|
||||
|
||||
// Load Strings file
|
||||
/*** Load main strings ***/
|
||||
|
||||
try {
|
||||
this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));
|
||||
} catch(err) {
|
||||
@ -216,6 +225,8 @@ DBot.prototype.reloadModules = function() {
|
||||
// Load the module data
|
||||
_.each([ 'commands', 'pages', 'api' ], function(property) {
|
||||
var propertyObj = {};
|
||||
|
||||
if(fs.existsSync(moduleDir + property + '.js')) {
|
||||
try {
|
||||
var propertyKey = require.resolve(moduleDir + property);
|
||||
if(propertyKey) delete require.cache[propertyKey];
|
||||
@ -223,6 +234,7 @@ DBot.prototype.reloadModules = function() {
|
||||
} catch(err) {
|
||||
console.log('Module error (' + module.name + ') in ' + property + ': ' + err);
|
||||
}
|
||||
}
|
||||
|
||||
if(!_.has(module, property)) module[property] = {};
|
||||
_.extend(module[property], propertyObj);
|
||||
|
Loading…
Reference in New Issue
Block a user