3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-18 00:22:35 +01:00
dbot/modules/command/commands.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2013-05-17 09:35:21 +02:00
var _ = require('underscore')._,
request = require('request');
2013-01-14 17:24:38 +01:00
var commands = function(dbot) {
return {
'~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', {
'command': commandName,
2013-01-14 17:24:38 +01:00
'usage': dbot.usage[commandName]
}));
} else {
2013-01-14 17:24:38 +01:00
event.reply(dbot.t('no_usage_info', {
'command': commandName
}));
}
},
'~help': function(event) {
var moduleName = event.params[1];
2013-05-17 09:35:21 +02:00
if(!moduleName || !_.has(dbot.modules, moduleName)) {
event.reply(dbot.t('usage', {
'command': '~help',
'usage': '~help [module]'
}));
2013-05-17 09:35:21 +02:00
event.reply(dbot.t('loaded_modules', {
'modules': _.keys(dbot.modules).join(', ')
}));
2013-05-17 09:35:21 +02:00
} else {
var helpLink = dbot.config.repoRoot +
'blob/master/modules/' + moduleName + '/README.md';
if(dbot.config[moduleName].help) {
helpLink = dbot.config[moduleName].help;
}
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', {
'module': moduleName,
2013-05-17 09:35:21 +02:00
'link': helpLink
}));
2013-05-17 09:35:21 +02:00
}
}
2013-01-14 17:24:38 +01:00
};
};
2013-01-14 17:24:38 +01:00
exports.fetch = function(dbot) {
return commands(dbot);
};