From 5677cad1fa008ed9b7a61f90a171535faf49b807 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Fri, 25 May 2012 16:45:47 +0100 Subject: [PATCH] Use jsbot ignore instead of having it build into the modules --- modules/autoshorten.js | 35 ++++++++++++++++------------------- modules/puns.js | 16 ++++++---------- modules/spelling.js | 33 +++++++++++++++------------------ modules/youare.js | 9 +++------ run.js | 2 +- 5 files changed, 41 insertions(+), 54 deletions(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 9574142..9ad8a86 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -11,28 +11,25 @@ var autoshorten = function(dbot) { return { 'listener': function(event) { - if((dbot.db.ignores.hasOwnProperty(event.user) && - dbot.db.ignores[event.user].include(name)) == false) { - var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; - var urlMatches = event.message.match(urlRegex); + var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; + var urlMatches = event.message.match(urlRegex); - if(urlMatches !== null && urlMatches[0].length > 80) { - 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 > 80) { + 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) { - event.reply(dbot.t('shorten_link', {'user': event.user}) + JSON.parse(response).surl); - }); + http.get(options, function(res) { + res.setEncoding('utf8'); + res.on('data', function (response) { + event.reply(dbot.t('shorten_link', {'user': event.user}) + JSON.parse(response).surl); }); - } + }); } }, diff --git a/modules/puns.js b/modules/puns.js index 1693c5f..099d31a 100644 --- a/modules/puns.js +++ b/modules/puns.js @@ -5,16 +5,12 @@ var puns = function(dbot) { return { 'listener': function(event) { event.user = dbot.cleanNick(event.user); - - if((dbot.db.ignores.hasOwnProperty(event.user) && - dbot.db.ignores[event.user].include(name)) == false) { - if(dbot.moduleNames.include('quotes') && - dbot.db.quoteArrs.hasOwnProperty(event.user)) { - event.message = '~q ' + event.user; - event.action = 'PRIVMSG'; - event.params = event.message.split(' '); - dbot.instance.emit(event) - } + if(dbot.moduleNames.include('quotes') && + dbot.db.quoteArrs.hasOwnProperty(event.user)) { + event.message = '~q ' + event.user; + event.action = 'PRIVMSG'; + event.params = event.message.split(' '); + dbot.instance.emit(event) } }, diff --git a/modules/spelling.js b/modules/spelling.js index 1e9cec3..e52e2fe 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -39,25 +39,22 @@ var spelling = function(dbot) { return { 'listener': function(event) { - if((dbot.db.ignores.hasOwnProperty(event.user) && - dbot.db.ignores[event.user].include(name)) == false) { - var q = event.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3); - var otherQ = event.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4); - if(q) { - correct(event, q[1] || q[2], event.user, function (e) { - event.reply(dbot.t('spelling_self', e)); - }); - } else if(otherQ) { - correct(event, otherQ[2] || otherQ[3], otherQ[1], function (e) { - event.reply(dbot.t('spelling_other', e)); - }); + var q = event.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3); + var otherQ = event.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4); + if(q) { + correct(event, q[1] || q[2], event.user, function (e) { + event.reply(dbot.t('spelling_self', e)); + }); + } else if(otherQ) { + correct(event, otherQ[2] || otherQ[3], otherQ[1], function (e) { + event.reply(dbot.t('spelling_other', e)); + }); + } else { + if(last.hasOwnProperty(event.channel)) { + last[event.channel][event.user] = event.message; } else { - if(last.hasOwnProperty(event.channel)) { - last[event.channel][event.user] = event.message; - } else { - last[event.channel] = { }; - last[event.channel][event.user] = event.message; - } + last[event.channel] = { }; + last[event.channel][event.user] = event.message; } } }, diff --git a/modules/youare.js b/modules/youare.js index bc7f553..3627b28 100644 --- a/modules/youare.js +++ b/modules/youare.js @@ -3,13 +3,10 @@ var youAre = function(dbot) { return { 'listener': function(event) { - if((dbot.db.ignores.hasOwnProperty(event.user) && - dbot.db.ignores[event.user].include(name)) == false) { - var key = event.message.valMatch(/(\bis\b|\bare\b)\s+([\w\s\d]*?)(\s+)?(,|\.|\band\b|$)/, 5); + var key = event.message.valMatch(/(\bis\b|\bare\b)\s+([\w\s\d]*?)(\s+)?(,|\.|\band\b|$)/, 5); - if(key && key[2] != "" && Number.prototype.chanceIn(1, 100) && event.user != 'aisbot') { - event.reply(event.user + ': You\'re ' + key[2] + '.'); - } + if(key && key[2] != "" && Number.prototype.chanceIn(1, 100) && event.user != 'aisbot') { + event.reply(event.user + ': You\'re ' + key[2] + '.'); } }, diff --git a/run.js b/run.js index cdf1fa1..5a633ad 100644 --- a/run.js +++ b/run.js @@ -53,7 +53,7 @@ var DBot = function(timers) { // Populate bot properties with config data this.name = this.config.name || 'dbox'; this.admin = this.config.admin || [ 'reality' ]; - this.moduleNames = this.config.modules || [ 'admin', 'command', 'dice', 'js', 'kick', 'puns', 'quotes', 'spelling', 'youare' ]; + this.moduleNames = this.config.modules || [ 'ignore', 'admin', 'command', 'dice', 'js', 'kick', 'puns', 'quotes', 'spelling', 'youare' ]; this.language = this.config.language || 'english'; // It's the user's responsibility to fill this data structure up properly in