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
|
||||
*/
|
||||
DatabaseDriver.prototype.createDB = function(name, driver, callback, schema) {
|
||||
DatabaseDriver.prototype.createDB = function(name, driver, schema, callback) {
|
||||
var params = { 'schema': schema };
|
||||
|
||||
if(driver == 'disk') params.dir = 'db';
|
||||
|
49
run.js
49
run.js
@ -171,13 +171,11 @@ DBot.prototype.reloadModules = function() {
|
||||
|
||||
try {
|
||||
var webKey = require.resolve(moduleDir + 'web');
|
||||
} catch(err) {
|
||||
}
|
||||
} catch(err) { }
|
||||
if(webKey) {
|
||||
delete require.cache[webKey];
|
||||
}
|
||||
|
||||
try {
|
||||
// Load the module config data
|
||||
var config = {};
|
||||
|
||||
@ -217,19 +215,27 @@ DBot.prototype.reloadModules = function() {
|
||||
this.db[dbKey] = {};
|
||||
}
|
||||
}, this);
|
||||
this.loadModule(name, this.db);
|
||||
} else {
|
||||
// Just use the name of the module for now, add dbKey iteration later
|
||||
this.ddb.createDB(name, config.dbType, function(db) {
|
||||
module.db = db;
|
||||
}.bind(this), {});
|
||||
this.ddb.createDB(name, config.dbType, {}, function(db) {
|
||||
this.loadModule(name, db);
|
||||
}.bind(this));
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
// Load the module itself
|
||||
this.save();
|
||||
};
|
||||
|
||||
// Load the module itself
|
||||
DBot.prototype.loadModule = function(name, db) {
|
||||
var moduleDir = './modules/' + name + '/';
|
||||
var rawModule = require(moduleDir + name);
|
||||
var module = rawModule.fetch(this);
|
||||
module.name = name;
|
||||
this.rawModules.push(rawModule);
|
||||
|
||||
module.name = name;
|
||||
module.db = db;
|
||||
module.config = this.config[name];
|
||||
|
||||
// Load the module data
|
||||
@ -242,8 +248,10 @@ DBot.prototype.reloadModules = function() {
|
||||
if(propertyKey) delete require.cache[propertyKey];
|
||||
propertyObj = require(moduleDir + property).fetch(this);
|
||||
} catch(err) {
|
||||
this.status[name] = 'Error loading ' + propertyKey + ': ' + err + ' - ' + err.stack.split('\n')[1].trim();
|
||||
console.log('Module error (' + module.name + ') in ' + property + ': ' + err);
|
||||
this.status[name] = 'Error loading ' + propertyKey +
|
||||
': ' + 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);
|
||||
_.each(module[property], function(item, itemName) {
|
||||
item.module = name;
|
||||
if(_.has(config, property) && _.has(config[property], itemName)) {
|
||||
_.extend(item, config[property][itemName]);
|
||||
if(_.has(module.config, property) && _.has(module.config[property], itemName)) {
|
||||
_.extend(item, module.config[property][itemName]);
|
||||
}
|
||||
module[property][itemName] = _.bind(item, module);
|
||||
_.extend(module[property][itemName], item);
|
||||
@ -289,17 +297,10 @@ DBot.prototype.reloadModules = function() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
console.log(module);
|
||||
console.log(this);
|
||||
|
||||
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();
|
||||
|
||||
@ -313,9 +314,7 @@ DBot.prototype.reloadModules = function() {
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.save();
|
||||
};
|
||||
}
|
||||
|
||||
DBot.prototype.cleanNick = function(key) {
|
||||
key = key.toLowerCase();
|
||||
|
Loading…
Reference in New Issue
Block a user