3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

Updated the case sensativity a bit.

My ultimate aim of having the database entries cased and then the code that gets them work out insensibly seems a little unrealistic as it's easier to lowercase the input rather than the keys in the DB. Maybe at a later date when I've looked at the database code.

Shouldn't affect any other modules as it's standalone (and no port issues this time).
This commit is contained in:
Alexander D Brown 2011-11-10 18:29:06 +00:00
parent 7e5c5d3ca1
commit 4d53a481bd

View File

@ -7,11 +7,12 @@ var quotes = function(dbot) {
'~q': function(data, params) { '~q': function(data, params) {
var q = data.message.valMatch(/^~q ([\d\w\s]*)/, 2); var q = data.message.valMatch(/^~q ([\d\w\s]*)/, 2);
if(q) { if(q) {
key = q[1].trim().toLowerCase(); q[1] = q[1].trim();
key = q[1].toLowerCase();
if(quotes.hasOwnProperty(key)) { if(quotes.hasOwnProperty(key)) {
dbot.say(data.channel, key + ': ' + quotes[key].random()); dbot.say(data.channel, q[1] + ': ' + quotes[key].random());
} else { } else {
dbot.say(data.channel, 'Nobody loves ' + key); dbot.say(data.channel, 'Nobody loves ' + q[1]);
} }
} }
}, },
@ -20,12 +21,14 @@ var quotes = function(dbot) {
if(params[2] === undefined) { if(params[2] === undefined) {
dbot.say(data.channel, 'Next time provide a search parameter. Commence incineration.'); dbot.say(data.channel, 'Next time provide a search parameter. Commence incineration.');
} else { } else {
if(!quotes.hasOwnProperty(params[1])) { params[1].trim();
key = params[1].toLowerCase();
if(!quotes.hasOwnProperty(key)) {
dbot.say(data.channel, 'That category has no quotes in it. Commence incineration.'); dbot.say(data.channel, 'That category has no quotes in it. Commence incineration.');
} else { } else {
var matches = []; var matches = [];
quotes[params[1]].each(function(quote) { quotes[key].each(function(quote) {
if(quote.indexOf(params[2]) != -1) { if(quote.indexOf(params[2]) != -1) {
matches.push(quote); matches.push(quote);
} }
@ -44,10 +47,11 @@ var quotes = function(dbot) {
if(rmAllowed == true || data.user == dbot.admin) { if(rmAllowed == true || data.user == dbot.admin) {
var q = data.message.valMatch(/^~rmlast ([\d\w\s]*)/, 2); var q = data.message.valMatch(/^~rmlast ([\d\w\s]*)/, 2);
if(q) { if(q) {
q[1] = q[1].trim().toLowerCase(); q[1] = q[1].trim()
key = q[1].toLowerCase();
if(quotes.hasOwnProperty(q[1])) { if(quotes.hasOwnProperty(q[1])) {
if(!dbot.db.locks.include(q[1])) { if(!dbot.db.locks.include(q[1])) {
var quote = quotes[q[1]].pop(); var quote = quotes[key].pop();
rmAllowed = false; rmAllowed = false;
dbot.say(data.channel, '\'' + quote + '\' removed from ' + q[1]); dbot.say(data.channel, '\'' + quote + '\' removed from ' + q[1]);
} else { } else {
@ -78,11 +82,12 @@ var quotes = function(dbot) {
'~qcount': function(data, params) { '~qcount': function(data, params) {
var q = data.message.valMatch(/^~qcount ([\d\w\s]*)/, 2); var q = data.message.valMatch(/^~qcount ([\d\w\s]*)/, 2);
if(q) { if(q) {
key = q[1].trim().toLowerCase(); q[1] = q[1].trim();
key = q[1].toLowerCase();
if(quotes.hasOwnProperty(key)) { if(quotes.hasOwnProperty(key)) {
dbot.say(data.channel, key + ' has ' + quotes[key].length + ' quotes.'); dbot.say(data.channel, q[1] + ' has ' + quotes[key].length + ' quotes.');
} else { } else {
dbot.say(data.channel, 'No quotes under ' + key); dbot.say(data.channel, 'No quotes under ' + q[1]);
} }
} }
}, },
@ -90,19 +95,19 @@ var quotes = function(dbot) {
'~qadd': function(data, params) { '~qadd': function(data, params) {
var q = data.message.valMatch(/^~qadd ([\d\w\s]*)=(.+)$/, 3); var q = data.message.valMatch(/^~qadd ([\d\w\s]*)=(.+)$/, 3);
if(q) { if(q) {
q[1] = q[1].toLowerCase(); key = q[1].toLowerCase();
if(!Object.isArray(quotes[q[1]])) { if(!Object.isArray(quotes[key])) {
quotes[q[1]] = []; quotes[key] = [];
} else { } else {
if (q[2] in quotes[q[1]]) { if (q[2] in quotes[key]) {
dbot.say(data.channel, 'Quote already in DB. Initiate incineration.'); dbot.say(data.channel, 'Quote already in DB. Initiate incineration.');
return; return;
} }
} }
quotes[q[1]].push(q[2]); quotes[key].push(q[2]);
addStack.push(q[1]); addStack.push(q[1]);
rmAllowed = true; rmAllowed = true;
dbot.say(data.channel, 'Quote saved in \'' + q[1] + '\' (' + quotes[q[1]].length + ')'); dbot.say(data.channel, 'Quote saved in \'' + q[1] + '\' (' + quotes[key].length + ')');
} else { } else {
dbot.say(data.channel, 'Invalid syntax. Initiate incineration.'); dbot.say(data.channel, 'Invalid syntax. Initiate incineration.');
} }
@ -111,10 +116,11 @@ var quotes = function(dbot) {
'~qset': function(data, params) { '~qset': function(data, params) {
var q = data.message.valMatch(/^~qset ([\d\w\s]*)=(.+)$/, 3); var q = data.message.valMatch(/^~qset ([\d\w\s]*)=(.+)$/, 3);
if(q) { if(q) {
q[1] = q[1].toLowerCase(); q[1] = q[1].trim();
if(!quotes.hasOwnProperty(q[1]) || (quotes.hasOwnProperty(q[1]) && key = q[1].toLowerCase();
quotes[q[1]].length == 1)) { if(!quotes.hasOwnProperty(key) || (quotes.hasOwnProperty(key) &&
quotes[q[1]] = [q[2]]; quotes[key].length == 1)) {
quotes[key] = [q[2]];
dbot.say(data.channel, 'Quote saved as ' + q[1]); dbot.say(data.channel, 'Quote saved as ' + q[1]);
} else { } else {
dbot.say(data.channel, 'No replacing arrays, you whore.'); dbot.say(data.channel, 'No replacing arrays, you whore.');