mirror of
https://github.com/reality/dbot.git
synced 2024-12-25 04:02:39 +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');
|
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,6 +225,8 @@ 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 = {};
|
||||||
|
|
||||||
|
if(fs.existsSync(moduleDir + property + '.js')) {
|
||||||
try {
|
try {
|
||||||
var propertyKey = require.resolve(moduleDir + property);
|
var propertyKey = require.resolve(moduleDir + property);
|
||||||
if(propertyKey) delete require.cache[propertyKey];
|
if(propertyKey) delete require.cache[propertyKey];
|
||||||
@ -223,6 +234,7 @@ DBot.prototype.reloadModules = function() {
|
|||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log('Module error (' + module.name + ') in ' + property + ': ' + 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