3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-30 16:09:27 +01:00
Conflicts:
	modules/quotes.js
	run.js
This commit is contained in:
Luke Slater 2011-11-10 20:30:06 +00:00
commit b253aa871c
2 changed files with 41 additions and 33 deletions

View File

@ -7,16 +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)) {
var output = quotes[key].random(); dbot.say(data.channel, q[1] + ': ' + quotes[key].random());
if(output.indexOf("glee") != -1) {
dbot.instance.send('KICK ' + data.channel + ' ' + data.user + ' :glee off dickhead');
} else { } else {
dbot.say(data.channel, key + ': ' + output); dbot.say(data.channel, 'Nobody loves ' + q[1]);
}
} else {
dbot.say(data.channel, 'Nobody loves ' + key);
} }
} }
}, },
@ -25,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);
} }
@ -49,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 {
@ -83,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]);
} }
} }
}, },
@ -95,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.');
} }
@ -116,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.');

23
run.js
View File

@ -100,20 +100,27 @@ DBot.prototype.reloadModules = function() {
} else { } else {
var q = data.message.valMatch(/^~([\d\w\s]*)/, 2); var q = data.message.valMatch(/^~([\d\w\s]*)/, 2);
if(q) { if(q) {
key = q[1].trim().toLowerCase(); q[1] = q[1].trim();
key = this.cleanNick(q[1])
if(this.db.quoteArrs.hasOwnProperty(key)) { if(this.db.quoteArrs.hasOwnProperty(key)) {
var output = this.db.quoteArrs[key].random(); this.say(data.channel, q[1] + ': ' + this.db.quoteArrs[key].random());
if(output.indexOf("glee") != -1) {
this.instance.send('KICK ' + data.channel + ' ' + data.user + ' :glee off dickhead');
} else { } else {
this.say(data.channel, key + ': ' + output); this.say(data.channel, 'Nobody loves ' + q[1]);
}
} else {
this.say(data.channel, 'Nobody loves ' + key);
} }
} }
} }
}.bind(this)); }.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); new DBot(modules, timers);