2013-01-14 17:02:40 +01:00
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
var commands = function(dbot) {
|
|
|
|
return {
|
2013-01-14 17:02:40 +01:00
|
|
|
'~usage': function(event) {
|
|
|
|
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
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'~help': function(event) {
|
|
|
|
var moduleName = event.params[1];
|
2013-03-20 22:47:01 +01:00
|
|
|
if(!moduleName) {
|
2013-03-20 23:18:06 +01:00
|
|
|
helpfulModules = _.filter(dbot.modules, function(element, index, array) {
|
|
|
|
return _.has(dbot.config[element], 'help');
|
|
|
|
});
|
|
|
|
|
2013-03-20 22:47:01 +01:00
|
|
|
event.reply(dbot.t('usage', {
|
|
|
|
'command': '~help',
|
|
|
|
'usage': '~help [module]'
|
|
|
|
}));
|
2013-03-20 23:18:06 +01:00
|
|
|
event.reply(dbot.t('loaded_modules_with_help', {
|
|
|
|
'modules': helpfulModules.join(', ')
|
|
|
|
}));
|
2013-03-20 22:47:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
if(!_.has(dbot.modules, moduleName)) {
|
2013-03-20 22:47:01 +01:00
|
|
|
if(_.has(dbot.commands, moduleName)) {
|
|
|
|
var moduleName = dbot.commands[moduleName].module;
|
|
|
|
} else {
|
|
|
|
var moduleName = undefined;
|
|
|
|
}
|
2013-01-14 17:02:40 +01:00
|
|
|
}
|
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
if(moduleName && _.has(dbot.config[moduleName], 'help')) {
|
|
|
|
var help = dbot.config[moduleName].help;
|
|
|
|
event.reply(dbot.t('help_link', {
|
2013-01-14 17:02:40 +01:00
|
|
|
'module': moduleName,
|
|
|
|
'link': help
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
if(!moduleName) {
|
|
|
|
moduleName = event.params[1];
|
|
|
|
}
|
2013-01-14 17:24:38 +01:00
|
|
|
event.reply(dbot.t('no_help', { 'module': moduleName }))
|
2013-01-14 17:02:40 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-14 17:24:38 +01:00
|
|
|
};
|
2013-01-14 17:02:40 +01:00
|
|
|
};
|
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return commands(dbot);
|
|
|
|
};
|