From ca8a8ca9c20e1858d192c07daf9a221d3e8adc44 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 12 Jan 2013 22:19:48 +0000 Subject: [PATCH] underscorisation for dent and ignore [#81] --- modules/dent/dent.js | 1 - modules/ignore/ignore.js | 67 ++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/modules/dent/dent.js b/modules/dent/dent.js index 2361cfa..3d5844e 100644 --- a/modules/dent/dent.js +++ b/modules/dent/dent.js @@ -16,7 +16,6 @@ var dent = function(dbot) { }, function(error, response, body) { event.reply('Status posted (probably).'); - console.log(body); }); } }; diff --git a/modules/ignore/ignore.js b/modules/ignore/ignore.js index 14fdd5a..a3c99cd 100644 --- a/modules/ignore/ignore.js +++ b/modules/ignore/ignore.js @@ -4,54 +4,69 @@ * 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)) { - event.reply(dbot.t('already_ignoring', {'user': event.user})); + 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})); + event.reply(dbot.t('invalid_ignore', { 'user': event.user })); } } }, '~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(', ')})); + if(_.isUndefined(module)) { + 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})); - } 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