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 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
};

View File

@ -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
};

View File

@ -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
};

View File

@ -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
}

View File

@ -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
};