2012-05-23 20:38:10 +02: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.
|
|
|
|
*/
|
2011-08-23 01:04:40 +02:00
|
|
|
var fs = require('fs');
|
2012-03-10 18:56:38 +01:00
|
|
|
var sys = require('sys')
|
|
|
|
var exec = require('child_process').exec;
|
2011-08-23 01:04:40 +02:00
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
var admin = function(dbot) {
|
2011-08-22 19:56:36 +02:00
|
|
|
var commands = {
|
2012-05-23 20:38:10 +02:00
|
|
|
// Join a channel
|
|
|
|
'join': function(event) {
|
|
|
|
var channel = event.params[1];
|
|
|
|
dbot.instance.join(event, channel);
|
|
|
|
event.reply(dbot.t('join', {'channel': channel}));
|
2011-08-22 19:56:36 +02:00
|
|
|
},
|
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
// Leave a channel
|
|
|
|
'part': function(event) {
|
|
|
|
var channel = event.params[1];
|
|
|
|
event.instance.part(event, channel);
|
|
|
|
event.reply(dbot.t('part', {'channel': channel}));
|
2011-09-12 19:11:32 +02:00
|
|
|
},
|
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
// Op admin caller in given channel
|
|
|
|
'opme': function(event) {
|
|
|
|
event.channel = event.params[1];
|
|
|
|
dbot.instance.mode(event, '+o ' + event.user);
|
2011-08-22 19:56:36 +02:00
|
|
|
},
|
|
|
|
|
2012-03-10 18:56:38 +01:00
|
|
|
// Do a git pull and reload
|
2012-05-23 20:38:10 +02:00
|
|
|
'greload': function(event) {
|
|
|
|
var child = exec("git pull", function (error, stdout, stderr) {
|
|
|
|
event.reply(dbot.t('gpull'));
|
|
|
|
commands.reload(event);
|
2012-03-10 18:56:38 +01:00
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
// Reload DB, translations and modules.
|
|
|
|
'reload': function(event) {
|
2011-08-24 17:15:42 +02:00
|
|
|
dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
2012-03-25 03:24:12 +02:00
|
|
|
dbot.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));
|
2011-08-24 17:15:42 +02:00
|
|
|
dbot.reloadModules();
|
2012-05-23 20:38:10 +02:00
|
|
|
event.reply(dbot.t('reload'));
|
2011-08-24 19:23:00 +02:00
|
|
|
},
|
2012-03-09 22:44:05 +01:00
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
// Say something in a channel (TODO probably doesn't work.)
|
|
|
|
'say': function(event) {
|
|
|
|
var channel = event.params[1];
|
|
|
|
if(event.params[1] === "@") {
|
|
|
|
var channel = event.channel;
|
|
|
|
}
|
|
|
|
var message = event.params.slice(2).join(' ');
|
|
|
|
dbot.say(event.server, channel, message);
|
2012-03-09 22:44:05 +01:00
|
|
|
},
|
2011-08-24 19:23:00 +02:00
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
// Load new module
|
|
|
|
'load': function(event) {
|
|
|
|
var moduleName = event.params[1];
|
|
|
|
dbot.moduleNames.push(moduleName);
|
2011-08-24 19:23:00 +02:00
|
|
|
dbot.reloadModules();
|
2012-05-23 20:38:10 +02:00
|
|
|
event.reply(dbot.t('load_module', {'moduleName': moduleName}));
|
2011-08-24 19:23:00 +02:00
|
|
|
},
|
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
// Unload a loaded module
|
|
|
|
'unload': function(event) {
|
|
|
|
var moduleName = event.params[1];
|
|
|
|
if(dbot.moduleNames.include(moduleName)) {
|
|
|
|
var cacheKey = require.resolve('../modules/' + moduleName);
|
2012-02-14 01:32:31 +01:00
|
|
|
delete require.cache[cacheKey];
|
2012-02-14 01:41:34 +01:00
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
var moduleIndex = dbot.moduleNames.indexOf(moduleName);
|
2012-02-14 01:41:34 +01:00
|
|
|
dbot.moduleNames.splice(moduleIndex, 1);
|
2011-08-24 19:23:00 +02:00
|
|
|
dbot.reloadModules();
|
2012-05-23 20:38:10 +02:00
|
|
|
|
|
|
|
event.reply(dbot.t('unload_module', {'moduleName': moduleName}));
|
2011-08-24 19:23:00 +02:00
|
|
|
} else {
|
2012-05-23 20:38:10 +02:00
|
|
|
event.reply(dbot.t('unload_error', {'moduleName': moduleName}));
|
2011-08-24 19:23:00 +02:00
|
|
|
}
|
2011-10-09 17:06:28 +02:00
|
|
|
},
|
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
// Ban user from command or *
|
|
|
|
'ban': function(event) {
|
|
|
|
var username = event.params[1];
|
|
|
|
var command = event.params[2];
|
|
|
|
|
|
|
|
if(!dbot.db.bans.hasOwnProperty(command)) {
|
|
|
|
dbot.db.bans[command] = [ ];
|
2011-10-09 17:06:28 +02:00
|
|
|
}
|
2012-05-23 20:38:10 +02:00
|
|
|
dbot.db.bans[command].push(username);
|
|
|
|
event.reply(dbot.t('banned', {'user': username, 'command': command}));
|
2011-10-09 17:15:44 +02:00
|
|
|
},
|
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
// Unban a user from command or *
|
|
|
|
'unban': function(event) {
|
|
|
|
var username = event.params[1];
|
|
|
|
var command = event.params[2];
|
|
|
|
if(dbot.db.bans.hasOwnProperty(command) && dbot.db.bans[command].include(username)) {
|
|
|
|
dbot.db.bans[command].splice(dbot.db.bans[command].indexOf(username), 1);
|
|
|
|
event.reply(dbot.t('unbanned', {'user': username, 'command': command}));
|
2011-10-09 17:15:44 +02:00
|
|
|
} else {
|
2012-05-23 20:38:10 +02:00
|
|
|
event.reply(dbot.t('unban_error', {'user': username}));
|
2011-10-09 17:15:44 +02:00
|
|
|
}
|
2011-10-12 19:09:55 +02:00
|
|
|
},
|
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
// Lock quote category so quotes can't be removed
|
|
|
|
'lock': function(event) {
|
|
|
|
var category = event.params[1];
|
|
|
|
dbot.db.locks.push(category);
|
|
|
|
event.reply(dbot.t('qlock', {'category': category}));
|
2011-08-22 19:56:36 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
2012-05-23 20:38:10 +02:00
|
|
|
'name': 'admin',
|
2011-08-22 19:56:36 +02:00
|
|
|
|
2012-05-23 20:38:10 +02:00
|
|
|
/**
|
|
|
|
* Run the appropriate admin command given the input (and user).
|
|
|
|
*/
|
|
|
|
'listener': function(event) {
|
|
|
|
var commandName = event.params[0];
|
|
|
|
if(commands.hasOwnProperty(commandName) && dbot.admin.include(event.user)) {
|
|
|
|
commands[commandName](event);
|
|
|
|
dbot.save();
|
2012-03-07 17:54:03 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-15 22:43:02 +02:00
|
|
|
'on': 'PRIVMSG',
|
|
|
|
'ignorable': false
|
2011-08-22 19:56:36 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
2012-05-23 20:38:10 +02:00
|
|
|
return admin(dbot);
|
2011-08-22 19:56:36 +02:00
|
|
|
};
|