2012-12-11 17:04:52 +01:00
|
|
|
/**
|
|
|
|
* Module Name: Ignore
|
|
|
|
* Description: Handles commands in which users can choose to ignore listeners
|
|
|
|
* and commands from certain modules. It also populates the JSBot instance with
|
|
|
|
* this information, since that actually performs the ignorance.
|
|
|
|
*/
|
2013-01-12 23:19:48 +01:00
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
2012-12-11 17:04:52 +01:00
|
|
|
var ignore = function(dbot) {
|
|
|
|
var commands = {
|
|
|
|
'~ignore': function(event) {
|
2013-01-22 01:00:11 +01:00
|
|
|
var user = dbot.api.users.resolveUser(event.server, event.user),
|
|
|
|
module = event.params[1],
|
|
|
|
ignorableModules = _.chain(dbot.modules)
|
|
|
|
.filter(function(module, name) {
|
|
|
|
return dbot.config[module].ignorable === true;
|
|
|
|
})
|
|
|
|
.pluck('name')
|
|
|
|
.value();
|
2012-12-11 17:04:52 +01:00
|
|
|
|
2013-01-12 23:19:48 +01:00
|
|
|
if(_.isUndefined(module)) {
|
|
|
|
event.reply(dbot.t('ignore_usage', {
|
|
|
|
'user': event.user,
|
|
|
|
'modules': ignorableModules.join(', ')
|
|
|
|
}));
|
2012-12-11 17:04:52 +01:00
|
|
|
} else {
|
2013-01-12 23:19:48 +01:00
|
|
|
if(_.include(ignorableModules, module)) {
|
2013-01-22 01:00:11 +01:00
|
|
|
if(_.has(dbot.db.ignores, user) && _.include(dbot.db.ignores[user], module)) {
|
2013-01-12 23:19:48 +01:00
|
|
|
event.reply(dbot.t('already_ignoring', { 'user': event.user }));
|
2012-12-11 17:04:52 +01:00
|
|
|
} else {
|
2013-01-12 23:19:48 +01:00
|
|
|
if(_.has(dbot.db.ignores, module)) {
|
2013-01-22 01:00:11 +01:00
|
|
|
dbot.db.ignores[user].push(module);
|
2012-12-11 17:04:52 +01:00
|
|
|
} else {
|
2013-01-22 01:00:11 +01:00
|
|
|
dbot.db.ignores[user] = [module];
|
2012-12-11 17:04:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dbot.instance.ignoreTag(event.user, module);
|
2013-01-12 23:19:48 +01:00
|
|
|
event.reply(dbot.t('ignored', {
|
|
|
|
'user': event.user,
|
|
|
|
'module': module
|
|
|
|
}));
|
2012-12-11 17:04:52 +01:00
|
|
|
}
|
|
|
|
} else {
|
2013-01-12 23:19:48 +01:00
|
|
|
event.reply(dbot.t('invalid_ignore', { 'user': event.user }));
|
2012-12-11 17:04:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'~unignore': function(event) {
|
2013-01-22 01:00:11 +01:00
|
|
|
var user = dbot.api.users.resolveUser(event.server, event.user),
|
|
|
|
module = event.params[1],
|
|
|
|
ignoredModules = [];
|
|
|
|
|
2013-01-12 23:19:48 +01:00
|
|
|
if(_.has(dbot.db.ignores, event.user)) {
|
2013-01-22 01:00:11 +01:00
|
|
|
ignoredModules = dbot.db.ignores[user];
|
2012-12-11 17:04:52 +01:00
|
|
|
}
|
|
|
|
|
2013-01-12 23:19:48 +01:00
|
|
|
if(_.isUndefined(module)) {
|
|
|
|
event.reply(dbot.t('unignore_usage', {
|
|
|
|
'user': event.user,
|
|
|
|
'modules': ignoredModules.join(', ')
|
|
|
|
}));
|
2012-12-11 17:04:52 +01:00
|
|
|
} else {
|
2013-01-12 23:19:48 +01:00
|
|
|
if(_.include(ignoredModules, module)) {
|
2013-01-22 01:00:11 +01:00
|
|
|
dbot.db.ignores[user].splice(dbot.db.ignores[user].indexOf(module), 1);
|
|
|
|
dbot.instance.removeIgnore(user, module)
|
2013-01-12 23:19:48 +01:00
|
|
|
event.reply(dbot.t('unignored', {
|
|
|
|
'user': event.user,
|
|
|
|
'module': module
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('invalid_unignore', { 'user': event.user }));
|
2012-12-11 17:04:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2013-01-15 00:02:55 +01:00
|
|
|
this.commands = commands;
|
2012-12-11 17:04:52 +01:00
|
|
|
|
2013-01-15 00:02:55 +01:00
|
|
|
this.onLoad = function() {
|
|
|
|
dbot.instance.clearIgnores();
|
|
|
|
_.each(dbot.db.ignores, function(ignores, user) {
|
|
|
|
_.each(ignores, function(ignore) {
|
|
|
|
dbot.instance.ignoreTag(user, ignore);
|
2013-01-12 23:19:48 +01:00
|
|
|
}, this);
|
2013-01-15 00:02:55 +01:00
|
|
|
}, this);
|
2012-12-11 17:04:52 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
2013-01-15 00:02:55 +01:00
|
|
|
return new ignore(dbot);
|
2012-12-11 17:04:52 +01:00
|
|
|
};
|