2012-12-11 17:04:52 +01:00
|
|
|
/**
|
|
|
|
* Module Name: Admin
|
|
|
|
* Description: Set of commands which only one who is a DepressionBot
|
2013-06-05 23:41:20 +02:00
|
|
|
* administrator can run.
|
2012-12-11 17:04:52 +01:00
|
|
|
*/
|
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) {
|
2013-06-04 02:06:41 +02:00
|
|
|
var configPath = dbot.config;
|
|
|
|
configKey = configKey.split('.');
|
2013-04-20 15:50:47 +02:00
|
|
|
|
2013-06-04 02:06:41 +02:00
|
|
|
for(var i=0;i<configKey.length;i++) {
|
|
|
|
if(_.has(configPath, configKey[i])) {
|
|
|
|
configPath = configPath[configKey[i]];
|
|
|
|
} else {
|
|
|
|
configPath = null;
|
|
|
|
break;
|
2013-04-20 18:08:34 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-04 02:06:41 +02:00
|
|
|
|
|
|
|
callback(configPath);
|
2013-06-05 22:13:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'setConfig': function(configKey, newOption, callback) {
|
2013-06-05 23:41:20 +02:00
|
|
|
var configPath = dbot.customConfig,
|
|
|
|
oldOption = null;
|
2013-06-05 22:13:40 +02:00
|
|
|
configKey = configKey.split('.');
|
|
|
|
|
|
|
|
for(var i=0;i<configKey.length-1;i++) {
|
2013-06-05 23:41:20 +02:00
|
|
|
if(!_.has(configPath, configKey[i])) {
|
|
|
|
configPath[configKey[i]] = {};
|
2013-06-05 22:13:40 +02:00
|
|
|
}
|
2013-06-05 23:41:20 +02:00
|
|
|
configPath = configPath[configKey[i]];
|
2013-06-05 22:13:40 +02:00
|
|
|
}
|
2013-06-05 23:41:20 +02:00
|
|
|
|
|
|
|
if(_.has(configPath, configKey[i])) {
|
|
|
|
oldOption = configPath[configKey[i]];
|
|
|
|
}
|
|
|
|
configPath[configKey[i]] = newOption;
|
2013-06-05 23:14:21 +02:00
|
|
|
|
|
|
|
this.internalAPI.saveConfig();
|
2013-06-06 00:59:37 +02:00
|
|
|
dbot.reloadModules();
|
2013-06-05 23:41:20 +02:00
|
|
|
callback(null, oldOption);
|
|
|
|
}.bind(this),
|
2013-06-05 23:00:52 +02:00
|
|
|
|
|
|
|
'saveConfig': function() {
|
|
|
|
var config = dbot.customConfig;
|
|
|
|
fs.writeFileSync('config.json', JSON.stringify(config, null, ' '));
|
2013-06-04 02:06:41 +02:00
|
|
|
}
|
|
|
|
};
|
2015-07-19 18:56:08 +02:00
|
|
|
|
|
|
|
this.onLoad = function() {
|
2015-07-19 19:03:18 +02:00
|
|
|
dbot.api.timers.addTimer(60000, function() {
|
2018-05-20 23:46:19 +02:00
|
|
|
dbot.save(function() {});
|
2015-07-19 19:03:18 +02:00
|
|
|
});
|
2015-07-19 18:56:08 +02:00
|
|
|
};
|
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
|
|
|
};
|