forked from GitHub/dbot
fix module loader. admin sets config keys onload. I am incredibly annoyed. [#331]
This commit is contained in:
parent
466cb12c94
commit
3cd4513fe4
@ -36,6 +36,25 @@ var admin = function(dbot) {
|
||||
}
|
||||
}.bind(this)
|
||||
};
|
||||
|
||||
this.onLoad = function() {
|
||||
var configMap = dbot.config;
|
||||
this.db.scan('config', function(config) {
|
||||
if(config) {
|
||||
var currentPath = configMap,
|
||||
key = config.key.split('.'),
|
||||
value = config.value;
|
||||
|
||||
for(var i=0;i<key.length-1;i++) {
|
||||
if(_.has(currentPath, key[i])) {
|
||||
currentPath = currentPath[key[i]];
|
||||
}
|
||||
}
|
||||
|
||||
currentPath[key[i]] = value;
|
||||
}
|
||||
}, function(err) { });
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
|
@ -164,7 +164,10 @@ var commands = function(dbot) {
|
||||
|
||||
event.reply(configPath + ": " + config + " -> " + newOption);
|
||||
config = newOption;
|
||||
this.db.save('config', configPath, { 'value': config }, function(err) {
|
||||
this.db.save('config', configPath, {
|
||||
'key': configPath,
|
||||
'value': config
|
||||
}, function(err) {
|
||||
dbot.reloadModules();
|
||||
});
|
||||
} else {
|
||||
@ -186,7 +189,10 @@ var commands = function(dbot) {
|
||||
if(_.isArray(config)) {
|
||||
event.reply(configPath + ": " + config + " << " + newOption);
|
||||
config.push(newOption);
|
||||
this.db.save('config', configPath, { 'value': config }, function(err) {
|
||||
this.db.save('config', configPath, {
|
||||
'key': configPath,
|
||||
'value': config
|
||||
}, function(err) {
|
||||
dbot.reloadModules();
|
||||
});
|
||||
} else {
|
||||
|
76
run.js
76
run.js
@ -131,12 +131,8 @@ DBot.prototype.reloadModules = function() {
|
||||
this.modules = {};
|
||||
this.commands = {};
|
||||
this.api = {};
|
||||
this.commandMap = {}; // Map of which commands belong to which modules
|
||||
this.usage = {};
|
||||
|
||||
// Load config changes
|
||||
_.extend(this.config, this.db.config);
|
||||
|
||||
try {
|
||||
this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));
|
||||
} catch(err) {
|
||||
@ -157,7 +153,6 @@ DBot.prototype.reloadModules = function() {
|
||||
require('./snippets');
|
||||
|
||||
this.instance.removeListeners();
|
||||
|
||||
_.each(moduleNames, function(name) {
|
||||
this.status[name] = true;
|
||||
var moduleDir = './modules/' + name + '/';
|
||||
@ -207,13 +202,29 @@ DBot.prototype.reloadModules = function() {
|
||||
}
|
||||
this.config[name] = config;
|
||||
|
||||
var loadModule = function(db) {
|
||||
// Groovy funky database shit
|
||||
if(!_.has(config, 'dbType') || config.dbType == 'olde') {
|
||||
// Generate missing DB keys
|
||||
_.each(config.dbKeys, function(dbKey) {
|
||||
if(!_.has(this.db, dbKey)) {
|
||||
this.db[dbKey] = {};
|
||||
}
|
||||
}, this);
|
||||
} else {
|
||||
// Just use the name of the module for now, add dbKey iteration later
|
||||
this.ddb.createDB(name, config.dbType, {}, function(db) {});
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
process.nextTick(function() {
|
||||
_.each(moduleNames, function(name) {
|
||||
var moduleDir = './modules/' + name + '/';
|
||||
var rawModule = require(moduleDir + name);
|
||||
var module = rawModule.fetch(this);
|
||||
this.rawModules.push(rawModule);
|
||||
|
||||
module.name = name;
|
||||
module.db = db;
|
||||
module.db = this.ddb.databanks[name];
|
||||
module.config = this.config[name];
|
||||
|
||||
// Load the module data
|
||||
@ -276,45 +287,26 @@ DBot.prototype.reloadModules = function() {
|
||||
}
|
||||
|
||||
this.modules[module.name] = module;
|
||||
|
||||
if(_.has(this.modules, 'web')) this.modules.web.reloadPages();
|
||||
|
||||
_.each(this.modules, function(module, name) {
|
||||
if(module.onLoad) {
|
||||
try {
|
||||
module.onLoad();
|
||||
} catch(err) {
|
||||
this.status[name] = 'Error in onLoad: ' + err + ' ' + err.stack.split('\n')[1].trim();
|
||||
console.log('MODULE ONLOAD ERROR (' + name + '): ' + err );
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
}.bind(this);
|
||||
|
||||
// Groovy funky database shit
|
||||
if(!_.has(config, 'dbType') || config.dbType == 'olde') {
|
||||
// Generate missing DB keys
|
||||
_.each(config.dbKeys, function(dbKey) {
|
||||
if(!_.has(this.db, dbKey)) {
|
||||
this.db[dbKey] = {};
|
||||
}
|
||||
}, this);
|
||||
loadModule(this.db);
|
||||
} else {
|
||||
// Just use the name of the module for now, add dbKey iteration later
|
||||
this.ddb.createDB(name, config.dbType, {}, function(db) {
|
||||
loadModule(db);
|
||||
});
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
|
||||
|
||||
process.nextTick(function() {
|
||||
if(_.has(this.modules, 'web')) this.modules.web.reloadPages();
|
||||
_.each(this.modules, function(module, name) {
|
||||
if(module.onLoad) {
|
||||
try {
|
||||
module.onLoad();
|
||||
} catch(err) {
|
||||
this.status[name] = 'Error in onLoad: ' + err + ' ' + err.stack.split('\n')[1].trim();
|
||||
console.log('MODULE ONLOAD ERROR (' + name + '): ' + err );
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
}.bind(this));
|
||||
|
||||
this.save();
|
||||
};
|
||||
|
||||
// Load the module itself
|
||||
DBot.prototype.loadModule = function(name, db) {
|
||||
}
|
||||
|
||||
DBot.prototype.cleanNick = function(key) {
|
||||
key = key.toLowerCase();
|
||||
while(key.endsWith("_")) {
|
||||
|
Loading…
Reference in New Issue
Block a user