2012-12-11 17:04:52 +01:00
|
|
|
/**
|
|
|
|
* Module Name: Admin
|
|
|
|
* Description: Set of commands which only one who is a DepressionBot
|
|
|
|
* administrator can run - as such, it has its own command execution listener.
|
|
|
|
*/
|
2013-01-12 18:36:59 +01:00
|
|
|
var fs = require('fs'),
|
2013-01-14 17:56:34 +01:00
|
|
|
_ = require('underscore')._;
|
2012-12-11 17:04:52 +01:00
|
|
|
|
|
|
|
var admin = function(dbot) {
|
2013-04-20 15:50:47 +02:00
|
|
|
this.internalAPI = {
|
|
|
|
'getCurrentConfig': function(configKey, callback) {
|
|
|
|
if(configKey) {
|
|
|
|
this.db.read('config', configKey, function(err, cRecord) {
|
|
|
|
if(cRecord) {
|
2013-04-22 16:22:35 +02:00
|
|
|
console.log('record found');
|
2013-04-20 15:50:47 +02:00
|
|
|
callback(cRecord.value)
|
|
|
|
} else {
|
|
|
|
var configPath = dbot.config;
|
|
|
|
configKey = configKey.split('.');
|
|
|
|
|
|
|
|
for(var i=0;i<configKey.length;i++) {
|
|
|
|
if(_.has(configPath, configKey[i])) {
|
|
|
|
configPath = configPath[configKey[i]];
|
|
|
|
} else {
|
|
|
|
callback(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
process.nextTick(function() {
|
|
|
|
callback(configPath);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
callback(dbot.config);
|
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
};
|
2013-04-20 18:08:34 +02:00
|
|
|
|
|
|
|
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);
|
2012-12-11 17:04:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
2013-01-14 17:56:34 +01:00
|
|
|
return new admin(dbot);
|
2012-12-11 17:04:52 +01:00
|
|
|
};
|