Added ignore checkers to all ignorable modules with listeners, bit messy but eh.

This commit is contained in:
Luke Slater 2012-04-15 22:04:58 +01:00
parent 0062dde196
commit a600cb5da5
5 changed files with 82 additions and 61 deletions

View File

@ -1,35 +1,39 @@
var http = require('http'); var http = require('http');
var autoshorten = function(dbot) { var autoshorten = function(dbot) {
var name = 'autoshorten';
var dbot = dbot; var dbot = dbot;
return { return {
'listener': function(data) { 'listener': function(data) {
var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; if((dbot.db.ignores.hasOwnProperty(data.user) &&
var urlMatches = data.message.match(urlRegex); 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) { if(urlMatches !== null && urlMatches[0].length > 65) {
var url = urlMatches[0]; // Only doing one, screw you. var url = urlMatches[0]; // Only doing one, screw you.
// TODO: Make this use a decent URL shortener. Mine is shit. // TODO: Make this use a decent URL shortener. Mine is shit.
var options = { var options = {
'host': 'nc.no.de', 'host': 'nc.no.de',
'port': 80, 'port': 80,
'path': '/mkurl?url=' + escape(url) 'path': '/mkurl?url=' + escape(url)
}; };
http.get(options, function(res) { http.get(options, function(res) {
res.setEncoding('utf8'); res.setEncoding('utf8');
res.on('data', function (response) { res.on('data', function (response) {
dbot.say(data.channel, 'Shortened link from ' + data.user + ': ' + JSON.parse(response).surl); dbot.say(data.channel, 'Shortened link from ' + data.user + ': ' + JSON.parse(response).surl);
});
}); });
}); }
} }
}, },
'on': 'PRIVMSG', 'on': 'PRIVMSG',
'name': 'autoshorten', 'name': name,
'ignorable': true 'ignorable': true
}; };

View File

@ -1,20 +1,24 @@
var puns = function(dbot) { var puns = function(dbot) {
var names = 'puns';
var dbot = dbot; var dbot = dbot;
return { return {
'listener': function(data) { 'listener': function(data) {
if(dbot.moduleNames.include('quotes')) { if((dbot.db.ignores.hasOwnProperty(data.user) &&
if(dbot.db.quoteArrs.hasOwnProperty(data.user.toLowerCase())) { dbot.db.ignores[data.user].include(name)) == false) {
data.message = '~q ' + data.user.toLowerCase(); if(dbot.moduleNames.include('quotes')) {
var params = data.message.split(' '); if(dbot.db.quoteArrs.hasOwnProperty(data.user.toLowerCase())) {
dbot.commands[params[0]](data, params); data.message = '~q ' + data.user.toLowerCase();
var params = data.message.split(' ');
dbot.commands[params[0]](data, params);
}
} }
} }
}, },
'on': 'JOIN', 'on': 'JOIN',
'name': 'puns', 'name': name,
'ignorable': true 'ignorable': true
}; };

View File

@ -1,4 +1,5 @@
var quotes = function(dbot) { var quotes = function(dbot) {
var name = 'quotes';
var quotes = dbot.db.quoteArrs; var quotes = dbot.db.quoteArrs;
var addStack = []; var addStack = [];
var rmAllowed = true; var rmAllowed = true;
@ -276,32 +277,35 @@ var quotes = function(dbot) {
// For automatic quote retrieval // For automatic quote retrieval
'listener': function(data, params) { 'listener': function(data, params) {
if(data.user == 'reality') { if((dbot.db.ignores.hasOwnProperty(data.user) &&
var once = data.message.valMatch(/^I ([\d\w\s,'-]* once)/, 2); dbot.db.ignores[data.user].include(name)) == false) {
} else { if(data.user == 'reality') {
var once = data.message.valMatch(/^reality ([\d\w\s,'-]* once)/, 2); var once = data.message.valMatch(/^I ([\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 { } else {
if(!dbot.db.quoteArrs.hasOwnProperty('realityonce')) { var once = data.message.valMatch(/^reality ([\d\w\s,'-]* once)/, 2);
dbot.db.quoteArrs['realityonce'] = []; }
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', 'on': 'PRIVMSG',
'name': 'quotes', 'name': name,
'ignorable': true 'ignorable': true
}; };

View File

@ -1,4 +1,5 @@
var spelling = function(dbot) { var spelling = function(dbot) {
var name = 'spelling';
var dbot = dbot; var dbot = dbot;
var last = {}; var last = {};
@ -38,29 +39,32 @@ var spelling = function(dbot) {
return { return {
'listener': function(data, params) { 'listener': function(data, params) {
var q = data.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3); if((dbot.db.ignores.hasOwnProperty(data.user) &&
var otherQ = data.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4); dbot.db.ignores[data.user].include(name)) == false) {
if(q) { var q = data.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3);
correct(data, q[1] || q[2], data.user, function (e) { var otherQ = data.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4);
dbot.say(data.channel, dbot.strings[dbot.language].spelling_self.format(e)); if(q) {
}); correct(data, q[1] || q[2], data.user, function (e) {
} else if(otherQ) { dbot.say(data.channel, dbot.strings[dbot.language].spelling_self.format(e));
correct(data, otherQ[2] || otherQ[3], otherQ[1], function (e) { });
dbot.say(data.channel, dbot.strings[dbot.language].spelling_other.format(e)); } else if(otherQ) {
}); correct(data, otherQ[2] || otherQ[3], otherQ[1], function (e) {
} else { dbot.say(data.channel, dbot.strings[dbot.language].spelling_other.format(e));
if(last.hasOwnProperty(data.channel)) { });
last[data.channel][data.user] = data.message;
} else { } else {
last[data.channel] = { }; if(last.hasOwnProperty(data.channel)) {
last[data.channel][data.user] = data.message; last[data.channel][data.user] = data.message;
} else {
last[data.channel] = { };
last[data.channel][data.user] = data.message;
}
} }
} }
}, },
'on': 'PRIVMSG', 'on': 'PRIVMSG',
'name': 'spelling', 'name': name,
'ignorable': true 'ignorable': true
} }

View File

@ -1,16 +1,21 @@
var youAre = function(dbot) { var youAre = function(dbot) {
var name = 'youare';
return { return {
'listener': function(data) { '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') { if(key && key[2] != "" && Number.prototype.chanceIn(1, 100) && data.user != 'aisbot') {
dbot.say(data.channel, data.user + ': You\'re ' + key[2] + '.'); dbot.say(data.channel, data.user + ': You\'re ' + key[2] + '.');
}
} }
}, },
'on': 'PRIVMSG', 'on': 'PRIVMSG',
'name': 'youare', 'name': name,
'ignorable': false 'ignorable': false
}; };