3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 11:42:36 +01:00

underscorisation for dent and ignore [#81]

This commit is contained in:
reality 2013-01-12 22:19:48 +00:00
parent 3cc013635d
commit ca8a8ca9c2
2 changed files with 40 additions and 28 deletions

View File

@ -16,7 +16,6 @@ var dent = function(dbot) {
},
function(error, response, body) {
event.reply('Status posted (probably).');
console.log(body);
});
}
};

View File

@ -4,31 +4,40 @@
* and commands from certain modules. It also populates the JSBot instance with
* this information, since that actually performs the ignorance.
*/
var _ = require('underscore')._;
var ignore = function(dbot) {
var commands = {
'~ignore': function(event) {
var ignorableModules = dbot.modules.filter(function(module) {
if(module.ignorable != null && module.ignorable == true) {
return true;
}
});
var module = event.params[1];
var ignorableModules = _.chain(dbot.modules)
.filter(function(module) {
return module.ignorable !== null && module.ignorable === true;
})
.pluck('name')
.value();
if(module === undefined) {
event.reply(dbot.t('ignore_usage', {'user': event.user, 'modules': ignorableModules.join(', ')}));
if(_.isUndefined(module)) {
event.reply(dbot.t('ignore_usage', {
'user': event.user,
'modules': ignorableModules.join(', ')
}));
} else {
if(ignorableModules.include(module)) {
if(dbot.db.ignores.hasOwnProperty(event.user) && dbot.db.ignores[event.user].include(module)) {
if(_.include(ignorableModules, module)) {
if(_.has(dbot.db.ignores, event.user) && _.include(dbot.db.ignores[event.user], module)) {
event.reply(dbot.t('already_ignoring', { 'user': event.user }));
} else {
if(dbot.db.ignores.hasOwnProperty(module)) {
if(_.has(dbot.db.ignores, module)) {
dbot.db.ignores[event.user].push(module);
} else {
dbot.db.ignores[event.user] = [module];
}
dbot.instance.ignoreTag(event.user, module);
event.reply(dbot.t('ignored', {'user': event.user, 'module': module}));
event.reply(dbot.t('ignored', {
'user': event.user,
'module': module
}));
}
} else {
event.reply(dbot.t('invalid_ignore', { 'user': event.user }));
@ -38,20 +47,26 @@ var ignore = function(dbot) {
'~unignore': function(event) {
var ignoredModules = [];
if(dbot.db.ignores.hasOwnProperty(event.user)) {
if(_.has(dbot.db.ignores, event.user)) {
ignoredModules = dbot.db.ignores[event.user];
}
var module = event.params[1];
if(module === undefined) {
event.reply(dbot.t('unignore_usage', {'user': event.user, 'modules': ignoredModules.join(', ')}));
} else {
if(ignoredModules.include(module) == false) {
event.reply(dbot.t('invalid_unignore', {'user': event.user}));
if(_.isUndefined(module)) {
event.reply(dbot.t('unignore_usage', {
'user': event.user,
'modules': ignoredModules.join(', ')
}));
} else {
if(_.include(ignoredModules, module)) {
dbot.db.ignores[event.user].splice(dbot.db.ignores[event.user].indexOf(module), 1);
dbot.instance.removeIgnore(event.user, module)
event.reply(dbot.t('unignored', {'user': event.user, 'module': module}));
event.reply(dbot.t('unignored', {
'user': event.user,
'module': module
}));
} else {
event.reply(dbot.t('invalid_unignore', { 'user': event.user }));
}
}
}
@ -64,13 +79,11 @@ var ignore = function(dbot) {
'onLoad': function() {
dbot.instance.clearIgnores();
for(var user in dbot.db.ignores) {
if(dbot.db.ignores.hasOwnProperty(user)) {
for(var i=0;i<dbot.db.ignores[user].length;i++) {
dbot.instance.ignoreTag(user, dbot.db.ignores[user][i]);
}
}
}
_.each(dbot.db.ignores, function(ignores, user) {
_.each(ignores, function(ignore) {
dbot.instance.ignoreTag(user, ignore);
}, this);
}, this);
}
};
};