From 4d53a481bd165053bed751361832ed6972d8ba3f Mon Sep 17 00:00:00 2001 From: Alexander D Brown Date: Thu, 10 Nov 2011 18:29:06 +0000 Subject: [PATCH 1/4] 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). --- modules/quotes.js | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/modules/quotes.js b/modules/quotes.js index 5c4854a..93edbeb 100644 --- a/modules/quotes.js +++ b/modules/quotes.js @@ -7,11 +7,12 @@ var quotes = function(dbot) { '~q': function(data, params) { var q = data.message.valMatch(/^~q ([\d\w\s]*)/, 2); if(q) { - key = q[1].trim().toLowerCase(); + q[1] = q[1].trim(); + key = q[1].toLowerCase(); if(quotes.hasOwnProperty(key)) { - dbot.say(data.channel, key + ': ' + quotes[key].random()); + dbot.say(data.channel, q[1] + ': ' + quotes[key].random()); } 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) { dbot.say(data.channel, 'Next time provide a search parameter. Commence incineration.'); } 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.'); } else { var matches = []; - quotes[params[1]].each(function(quote) { + quotes[key].each(function(quote) { if(quote.indexOf(params[2]) != -1) { matches.push(quote); } @@ -44,10 +47,11 @@ var quotes = function(dbot) { if(rmAllowed == true || data.user == dbot.admin) { var q = data.message.valMatch(/^~rmlast ([\d\w\s]*)/, 2); if(q) { - q[1] = q[1].trim().toLowerCase(); + q[1] = q[1].trim() + key = q[1].toLowerCase(); if(quotes.hasOwnProperty(q[1])) { if(!dbot.db.locks.include(q[1])) { - var quote = quotes[q[1]].pop(); + var quote = quotes[key].pop(); rmAllowed = false; dbot.say(data.channel, '\'' + quote + '\' removed from ' + q[1]); } else { @@ -78,11 +82,12 @@ var quotes = function(dbot) { '~qcount': function(data, params) { var q = data.message.valMatch(/^~qcount ([\d\w\s]*)/, 2); if(q) { - key = q[1].trim().toLowerCase(); + q[1] = q[1].trim(); + key = q[1].toLowerCase(); 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 { - 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) { var q = data.message.valMatch(/^~qadd ([\d\w\s]*)=(.+)$/, 3); if(q) { - q[1] = q[1].toLowerCase(); - if(!Object.isArray(quotes[q[1]])) { - quotes[q[1]] = []; + key = q[1].toLowerCase(); + if(!Object.isArray(quotes[key])) { + quotes[key] = []; } else { - if (q[2] in quotes[q[1]]) { + if (q[2] in quotes[key]) { dbot.say(data.channel, 'Quote already in DB. Initiate incineration.'); return; } } - quotes[q[1]].push(q[2]); + quotes[key].push(q[2]); addStack.push(q[1]); 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 { dbot.say(data.channel, 'Invalid syntax. Initiate incineration.'); } @@ -111,10 +116,11 @@ var quotes = function(dbot) { '~qset': function(data, params) { var q = data.message.valMatch(/^~qset ([\d\w\s]*)=(.+)$/, 3); if(q) { - q[1] = q[1].toLowerCase(); - if(!quotes.hasOwnProperty(q[1]) || (quotes.hasOwnProperty(q[1]) && - quotes[q[1]].length == 1)) { - quotes[q[1]] = [q[2]]; + q[1] = q[1].trim(); + key = q[1].toLowerCase(); + if(!quotes.hasOwnProperty(key) || (quotes.hasOwnProperty(key) && + quotes[key].length == 1)) { + quotes[key] = [q[2]]; dbot.say(data.channel, 'Quote saved as ' + q[1]); } else { dbot.say(data.channel, 'No replacing arrays, you whore.'); From 35679ac19e34444d74973b4392629fe161d53d85 Mon Sep 17 00:00:00 2001 From: Alexander D Brown Date: Thu, 10 Nov 2011 18:59:25 +0000 Subject: [PATCH 2/4] Forgot the widly used ~keyname syntax in run.js --- run.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/run.js b/run.js index 109701c..024c015 100644 --- a/run.js +++ b/run.js @@ -100,11 +100,12 @@ DBot.prototype.reloadModules = function() { } else { var q = data.message.valMatch(/^~([\d\w\s]*)/, 2); if(q) { - key = q[1].trim().toLowerCase(); + q[1] = q[1].tirm(); + key = q[1].toLowerCase(); if(this.db.quoteArrs.hasOwnProperty(key)) { - this.say(data.channel, key + ': ' + this.db.quoteArrs[key].random()); + this.say(data.channel, q[1] + ': ' + this.db.quoteArrs[key].random()); } else { - this.say(data.channel, 'Nobody loves ' + key); + this.say(data.channel, 'Nobody loves ' + q[1]); } } } From 0784e2c5befdef076101791bbb494155e227c88b Mon Sep 17 00:00:00 2001 From: Alexander D Brown Date: Thu, 10 Nov 2011 19:05:19 +0000 Subject: [PATCH 3/4] Derp. Had 'tirm' instead of 'trim'. --- run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.js b/run.js index 024c015..4ae8b67 100644 --- a/run.js +++ b/run.js @@ -100,7 +100,7 @@ DBot.prototype.reloadModules = function() { } else { var q = data.message.valMatch(/^~([\d\w\s]*)/, 2); if(q) { - q[1] = q[1].tirm(); + q[1] = q[1].trim(); key = q[1].toLowerCase(); if(this.db.quoteArrs.hasOwnProperty(key)) { this.say(data.channel, q[1] + ': ' + this.db.quoteArrs[key].random()); From 03e608ffb1d5f65f73dd1b6d0f6b1c3a6998ec87 Mon Sep 17 00:00:00 2001 From: Alexander D Brown Date: Thu, 10 Nov 2011 19:36:01 +0000 Subject: [PATCH 4/4] Added in a feature to remove underscores ('_') from the ends of nicks. The aim of this feature is display the same messages for users logged in more that once under the same nick (it's common to see 'nick' and 'nick_', etc. for those with bad connections). Of course there are users that won't conform to this, but short of messing around with hostnames it's the best I've got so far (perhaps ~qalias nick=alt_nick could be a future addition to this). --- run.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/run.js b/run.js index 4ae8b67..20b92de 100644 --- a/run.js +++ b/run.js @@ -101,7 +101,7 @@ DBot.prototype.reloadModules = function() { var q = data.message.valMatch(/^~([\d\w\s]*)/, 2); if(q) { q[1] = q[1].trim(); - key = q[1].toLowerCase(); + key = this.cleanNick(q[1]) if(this.db.quoteArrs.hasOwnProperty(key)) { this.say(data.channel, q[1] + ': ' + this.db.quoteArrs[key].random()); } else { @@ -112,4 +112,15 @@ DBot.prototype.reloadModules = function() { }.bind(this)); }; +DBot.prototype.cleanNick = function(key) { + key = key.toLowerCase(); + while(key.endsWith("_")) { + if(this.db.quoteArrs.hasOwnProperty(key)) { + return key; + } + key = key.substring(0, key.length-1); + } + return key; +} + new DBot(modules, timers);