2013-05-17 09:35:21 +02:00
|
|
|
var _ = require('underscore')._,
|
|
|
|
request = require('request');
|
2013-01-14 17:02:40 +01:00
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
var commands = function(dbot) {
|
2014-09-13 21:48:28 +02:00
|
|
|
var commands = {
|
2013-12-29 19:13:59 +01:00
|
|
|
'usage': function(event) {
|
2013-01-14 17:02:40 +01:00
|
|
|
var commandName = event.params[1];
|
2013-01-14 17:24:38 +01:00
|
|
|
if(_.has(dbot.usage, commandName)) {
|
|
|
|
event.reply(dbot.t('usage', {
|
2013-01-14 17:02:40 +01:00
|
|
|
'command': commandName,
|
2013-01-14 17:24:38 +01:00
|
|
|
'usage': dbot.usage[commandName]
|
2013-01-14 17:02:40 +01:00
|
|
|
}));
|
|
|
|
} else {
|
2013-01-14 17:24:38 +01:00
|
|
|
event.reply(dbot.t('no_usage_info', {
|
2013-01-14 17:02:40 +01:00
|
|
|
'command': commandName
|
|
|
|
}));
|
|
|
|
}
|
2013-06-06 00:26:10 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'~commands': function(event) {
|
|
|
|
var name = event.params[1];
|
|
|
|
if(_.has(dbot.modules, name)) {
|
|
|
|
var commands = _.keys(dbot.commands);
|
|
|
|
commands = _.filter(commands, function(cName) {
|
|
|
|
return dbot.commands[cName].module == name;
|
|
|
|
});
|
|
|
|
event.reply(dbot.t('module_commands', {
|
|
|
|
'module': name,
|
|
|
|
'commands': commands.join(', ')
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('loaded_modules', {
|
|
|
|
'modules': _.keys(dbot.modules).join(', ')
|
|
|
|
}));
|
|
|
|
}
|
2013-01-14 17:02:40 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
'~help': function(event) {
|
|
|
|
var moduleName = event.params[1];
|
2013-05-17 09:35:21 +02:00
|
|
|
if(!moduleName || !_.has(dbot.modules, moduleName)) {
|
2013-03-20 22:47:01 +01:00
|
|
|
event.reply(dbot.t('usage', {
|
2013-12-29 20:11:44 +01:00
|
|
|
'command': this.config.commandPrefix + 'help',
|
|
|
|
'usage': this.config.commandPrefix + 'help [module]'
|
2013-03-20 22:47:01 +01:00
|
|
|
}));
|
2013-05-17 09:35:21 +02:00
|
|
|
event.reply(dbot.t('loaded_modules', {
|
|
|
|
'modules': _.keys(dbot.modules).join(', ')
|
2013-03-20 23:18:06 +01:00
|
|
|
}));
|
2013-05-17 09:35:21 +02:00
|
|
|
} else {
|
|
|
|
var helpLink = dbot.config.repoRoot +
|
|
|
|
'blob/master/modules/' + moduleName + '/README.md';
|
2013-06-27 20:28:35 +02:00
|
|
|
if(dbot.config.modules[moduleName].help) {
|
|
|
|
helpLink = dbot.config.modules[moduleName].help;
|
2013-03-20 22:47:01 +01:00
|
|
|
}
|
2013-01-14 17:02:40 +01:00
|
|
|
|
2013-05-17 09:35:21 +02:00
|
|
|
// TODO: Check it exists
|
2013-01-14 17:24:38 +01:00
|
|
|
event.reply(dbot.t('help_link', {
|
2013-01-14 17:02:40 +01:00
|
|
|
'module': moduleName,
|
2013-05-17 09:35:21 +02:00
|
|
|
'link': helpLink
|
2013-01-14 17:02:40 +01:00
|
|
|
}));
|
2013-05-17 09:35:21 +02:00
|
|
|
}
|
2013-01-14 17:02:40 +01:00
|
|
|
}
|
2013-01-14 17:24:38 +01:00
|
|
|
};
|
2014-09-13 21:48:28 +02:00
|
|
|
commands['usage'].regex = [/usage ([^ ]+)/, 2];
|
|
|
|
|
|
|
|
return commands;
|
2013-01-14 17:02:40 +01:00
|
|
|
};
|
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return commands(dbot);
|
|
|
|
};
|