forked from GitHub/dbot
Hacked up run.js so db is definitely loaded by time onLoad is run. Need to clear up
This commit is contained in:
parent
5c48971034
commit
228a2611a5
@ -12,7 +12,7 @@ var DatabaseDriver = function() {
|
|||||||
/**
|
/**
|
||||||
* Connect to or create a new DataBank
|
* Connect to or create a new DataBank
|
||||||
*/
|
*/
|
||||||
DatabaseDriver.prototype.createDB = function(name, driver, callback, schema) {
|
DatabaseDriver.prototype.createDB = function(name, driver, schema, callback) {
|
||||||
var params = { 'schema': schema };
|
var params = { 'schema': schema };
|
||||||
|
|
||||||
if(driver == 'disk') params.dir = 'db';
|
if(driver == 'disk') params.dir = 'db';
|
||||||
|
47
run.js
47
run.js
@ -171,13 +171,11 @@ DBot.prototype.reloadModules = function() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
var webKey = require.resolve(moduleDir + 'web');
|
var webKey = require.resolve(moduleDir + 'web');
|
||||||
} catch(err) {
|
} catch(err) { }
|
||||||
}
|
|
||||||
if(webKey) {
|
if(webKey) {
|
||||||
delete require.cache[webKey];
|
delete require.cache[webKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
// Load the module config data
|
// Load the module config data
|
||||||
var config = {};
|
var config = {};
|
||||||
|
|
||||||
@ -217,19 +215,27 @@ DBot.prototype.reloadModules = function() {
|
|||||||
this.db[dbKey] = {};
|
this.db[dbKey] = {};
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
this.loadModule(name, this.db);
|
||||||
} else {
|
} else {
|
||||||
// Just use the name of the module for now, add dbKey iteration later
|
// Just use the name of the module for now, add dbKey iteration later
|
||||||
this.ddb.createDB(name, config.dbType, function(db) {
|
this.ddb.createDB(name, config.dbType, {}, function(db) {
|
||||||
module.db = db;
|
this.loadModule(name, db);
|
||||||
}.bind(this), {});
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
this.save();
|
||||||
|
};
|
||||||
|
|
||||||
// Load the module itself
|
// Load the module itself
|
||||||
|
DBot.prototype.loadModule = function(name, db) {
|
||||||
|
var moduleDir = './modules/' + name + '/';
|
||||||
var rawModule = require(moduleDir + name);
|
var rawModule = require(moduleDir + name);
|
||||||
var module = rawModule.fetch(this);
|
var module = rawModule.fetch(this);
|
||||||
module.name = name;
|
|
||||||
this.rawModules.push(rawModule);
|
this.rawModules.push(rawModule);
|
||||||
|
|
||||||
|
module.name = name;
|
||||||
|
module.db = db;
|
||||||
module.config = this.config[name];
|
module.config = this.config[name];
|
||||||
|
|
||||||
// Load the module data
|
// Load the module data
|
||||||
@ -242,8 +248,10 @@ DBot.prototype.reloadModules = function() {
|
|||||||
if(propertyKey) delete require.cache[propertyKey];
|
if(propertyKey) delete require.cache[propertyKey];
|
||||||
propertyObj = require(moduleDir + property).fetch(this);
|
propertyObj = require(moduleDir + property).fetch(this);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
this.status[name] = 'Error loading ' + propertyKey + ': ' + err + ' - ' + err.stack.split('\n')[1].trim();
|
this.status[name] = 'Error loading ' + propertyKey +
|
||||||
console.log('Module error (' + module.name + ') in ' + property + ': ' + err);
|
': ' + err + ' - ' + err.stack.split('\n')[1].trim();
|
||||||
|
console.log('Module error (' + module.name + ') in ' +
|
||||||
|
property + ': ' + err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,8 +259,8 @@ DBot.prototype.reloadModules = function() {
|
|||||||
_.extend(module[property], propertyObj);
|
_.extend(module[property], propertyObj);
|
||||||
_.each(module[property], function(item, itemName) {
|
_.each(module[property], function(item, itemName) {
|
||||||
item.module = name;
|
item.module = name;
|
||||||
if(_.has(config, property) && _.has(config[property], itemName)) {
|
if(_.has(module.config, property) && _.has(module.config[property], itemName)) {
|
||||||
_.extend(item, config[property][itemName]);
|
_.extend(item, module.config[property][itemName]);
|
||||||
}
|
}
|
||||||
module[property][itemName] = _.bind(item, module);
|
module[property][itemName] = _.bind(item, module);
|
||||||
_.extend(module[property][itemName], item);
|
_.extend(module[property][itemName], item);
|
||||||
@ -289,17 +297,10 @@ DBot.prototype.reloadModules = function() {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(module);
|
||||||
|
console.log(this);
|
||||||
|
|
||||||
this.modules[module.name] = module;
|
this.modules[module.name] = module;
|
||||||
} catch(err) {
|
|
||||||
console.log(this.t('module_load_error', {'moduleName': name}));
|
|
||||||
this.status[name] = err + ' - ' + err.stack.split('\n')[1].trim();
|
|
||||||
if(this.config.debugMode) {
|
|
||||||
console.log('MODULE ERROR (' + name + '): ' + err.stack );
|
|
||||||
} else {
|
|
||||||
console.log('MODULE ERROR (' + name + '): ' + err );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
if(_.has(this.modules, 'web')) this.modules.web.reloadPages();
|
if(_.has(this.modules, 'web')) this.modules.web.reloadPages();
|
||||||
|
|
||||||
@ -313,9 +314,7 @@ DBot.prototype.reloadModules = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
}
|
||||||
this.save();
|
|
||||||
};
|
|
||||||
|
|
||||||
DBot.prototype.cleanNick = function(key) {
|
DBot.prototype.cleanNick = function(key) {
|
||||||
key = key.toLowerCase();
|
key = key.toLowerCase();
|
||||||
|
Loading…
Reference in New Issue
Block a user