From a600cb5da5cfc8429e99cda40717ea9ccd2d860c Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 15 Apr 2012 22:04:58 +0100 Subject: [PATCH] Added ignore checkers to all ignorable modules with listeners, bit messy but eh. --- modules/autoshorten.js | 38 +++++++++++++++++++++----------------- modules/puns.js | 16 ++++++++++------ modules/quotes.js | 40 ++++++++++++++++++++++------------------ modules/spelling.js | 36 ++++++++++++++++++++---------------- modules/youare.js | 13 +++++++++---- 5 files changed, 82 insertions(+), 61 deletions(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index eb0cf7c..0598ce9 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -1,35 +1,39 @@ var http = require('http'); var autoshorten = function(dbot) { + var name = 'autoshorten'; var dbot = dbot; return { 'listener': function(data) { - var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; - var urlMatches = data.message.match(urlRegex); + if((dbot.db.ignores.hasOwnProperty(data.user) && + dbot.db.ignores[data.user].include(name)) == false) { + var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; + var urlMatches = data.message.match(urlRegex); - if(urlMatches !== null && urlMatches[0].length > 65) { - var url = urlMatches[0]; // Only doing one, screw you. - - // TODO: Make this use a decent URL shortener. Mine is shit. - var options = { - 'host': 'nc.no.de', - 'port': 80, - 'path': '/mkurl?url=' + escape(url) - }; + if(urlMatches !== null && urlMatches[0].length > 65) { + var url = urlMatches[0]; // Only doing one, screw you. + + // TODO: Make this use a decent URL shortener. Mine is shit. + var options = { + 'host': 'nc.no.de', + 'port': 80, + 'path': '/mkurl?url=' + escape(url) + }; - http.get(options, function(res) { - res.setEncoding('utf8'); - res.on('data', function (response) { - dbot.say(data.channel, 'Shortened link from ' + data.user + ': ' + JSON.parse(response).surl); + http.get(options, function(res) { + res.setEncoding('utf8'); + res.on('data', function (response) { + dbot.say(data.channel, 'Shortened link from ' + data.user + ': ' + JSON.parse(response).surl); + }); }); - }); + } } }, 'on': 'PRIVMSG', - 'name': 'autoshorten', + 'name': name, 'ignorable': true }; diff --git a/modules/puns.js b/modules/puns.js index 675f92c..0aa27dc 100644 --- a/modules/puns.js +++ b/modules/puns.js @@ -1,20 +1,24 @@ var puns = function(dbot) { + var names = 'puns'; var dbot = dbot; return { 'listener': function(data) { - if(dbot.moduleNames.include('quotes')) { - if(dbot.db.quoteArrs.hasOwnProperty(data.user.toLowerCase())) { - data.message = '~q ' + data.user.toLowerCase(); - var params = data.message.split(' '); - dbot.commands[params[0]](data, params); + if((dbot.db.ignores.hasOwnProperty(data.user) && + dbot.db.ignores[data.user].include(name)) == false) { + if(dbot.moduleNames.include('quotes')) { + if(dbot.db.quoteArrs.hasOwnProperty(data.user.toLowerCase())) { + data.message = '~q ' + data.user.toLowerCase(); + var params = data.message.split(' '); + dbot.commands[params[0]](data, params); + } } } }, 'on': 'JOIN', - 'name': 'puns', + 'name': name, 'ignorable': true }; diff --git a/modules/quotes.js b/modules/quotes.js index fdbf6d3..50f2921 100644 --- a/modules/quotes.js +++ b/modules/quotes.js @@ -1,4 +1,5 @@ var quotes = function(dbot) { + var name = 'quotes'; var quotes = dbot.db.quoteArrs; var addStack = []; var rmAllowed = true; @@ -276,32 +277,35 @@ var quotes = function(dbot) { // For automatic quote retrieval 'listener': function(data, params) { - if(data.user == 'reality') { - var once = data.message.valMatch(/^I ([\d\w\s,'-]* once)/, 2); - } else { - var once = data.message.valMatch(/^reality ([\d\w\s,'-]* once)/, 2); - } - - if(once) { - if((dbot.db.bans.hasOwnProperty('~qadd') && - dbot.db.bans['~qadd'].include(data.user)) || - dbot.db.bans['*'].include(data.user)) { - dbot.say(data.channel, data.user + ' is banned from using this command. Commence incineration.'); + if((dbot.db.ignores.hasOwnProperty(data.user) && + dbot.db.ignores[data.user].include(name)) == false) { + if(data.user == 'reality') { + var once = data.message.valMatch(/^I ([\d\w\s,'-]* once)/, 2); } else { - if(!dbot.db.quoteArrs.hasOwnProperty('realityonce')) { - dbot.db.quoteArrs['realityonce'] = []; + var once = data.message.valMatch(/^reality ([\d\w\s,'-]* once)/, 2); + } + + if(once) { + if((dbot.db.bans.hasOwnProperty('~qadd') && + dbot.db.bans['~qadd'].include(data.user)) || + dbot.db.bans['*'].include(data.user)) { + dbot.say(data.channel, data.user + ' is banned from using this command. Commence incineration.'); + } else { + if(!dbot.db.quoteArrs.hasOwnProperty('realityonce')) { + dbot.db.quoteArrs['realityonce'] = []; + } + dbot.db.quoteArrs['realityonce'].push('reality ' + once[1] + '.'); + addStack.push('realityonce'); + rmAllowed = true; + dbot.instance.say(data.channel, '\'reality ' + once[1] + '.\' saved.'); } - dbot.db.quoteArrs['realityonce'].push('reality ' + once[1] + '.'); - addStack.push('realityonce'); - rmAllowed = true; - dbot.instance.say(data.channel, '\'reality ' + once[1] + '.\' saved.'); } } }, 'on': 'PRIVMSG', - 'name': 'quotes', + 'name': name, 'ignorable': true }; diff --git a/modules/spelling.js b/modules/spelling.js index bfd1c77..8fed950 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -1,4 +1,5 @@ var spelling = function(dbot) { + var name = 'spelling'; var dbot = dbot; var last = {}; @@ -38,29 +39,32 @@ var spelling = function(dbot) { return { 'listener': function(data, params) { - var q = data.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3); - var otherQ = data.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4); - if(q) { - correct(data, q[1] || q[2], data.user, function (e) { - dbot.say(data.channel, dbot.strings[dbot.language].spelling_self.format(e)); - }); - } else if(otherQ) { - correct(data, otherQ[2] || otherQ[3], otherQ[1], function (e) { - dbot.say(data.channel, dbot.strings[dbot.language].spelling_other.format(e)); - }); - } else { - if(last.hasOwnProperty(data.channel)) { - last[data.channel][data.user] = data.message; + if((dbot.db.ignores.hasOwnProperty(data.user) && + dbot.db.ignores[data.user].include(name)) == false) { + var q = data.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3); + var otherQ = data.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4); + if(q) { + correct(data, q[1] || q[2], data.user, function (e) { + dbot.say(data.channel, dbot.strings[dbot.language].spelling_self.format(e)); + }); + } else if(otherQ) { + correct(data, otherQ[2] || otherQ[3], otherQ[1], function (e) { + dbot.say(data.channel, dbot.strings[dbot.language].spelling_other.format(e)); + }); } else { - last[data.channel] = { }; - last[data.channel][data.user] = data.message; + if(last.hasOwnProperty(data.channel)) { + last[data.channel][data.user] = data.message; + } else { + last[data.channel] = { }; + last[data.channel][data.user] = data.message; + } } } }, 'on': 'PRIVMSG', - 'name': 'spelling', + 'name': name, 'ignorable': true } diff --git a/modules/youare.js b/modules/youare.js index 7152f3d..2321a39 100644 --- a/modules/youare.js +++ b/modules/youare.js @@ -1,16 +1,21 @@ var youAre = function(dbot) { + var name = 'youare'; + return { 'listener': function(data) { - var key = data.message.valMatch(/(\bis\b|\bare\b)\s+([\w\s\d]*?)(\s+)?(,|\.|\band\b|$)/, 5); + if((dbot.db.ignores.hasOwnProperty(data.user) && + dbot.db.ignores[data.user].include(name)) == false) { + var key = data.message.valMatch(/(\bis\b|\bare\b)\s+([\w\s\d]*?)(\s+)?(,|\.|\band\b|$)/, 5); - if(key && key[2] != "" && Number.prototype.chanceIn(1, 100) && data.user != 'aisbot') { - dbot.say(data.channel, data.user + ': You\'re ' + key[2] + '.'); + if(key && key[2] != "" && Number.prototype.chanceIn(1, 100) && data.user != 'aisbot') { + dbot.say(data.channel, data.user + ': You\'re ' + key[2] + '.'); + } } }, 'on': 'PRIVMSG', - 'name': 'youare', + 'name': name, 'ignorable': false };