From 4290126222106a5558320eab2ddcfe03c2c9bec9 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 14 Apr 2012 06:06:40 +0100 Subject: [PATCH 01/33] autoshorten --- modules/autoshorten.js | 30 ++++++++++++++++++++++++++++++ modules/command.js | 1 + 2 files changed, 31 insertions(+) create mode 100644 modules/autoshorten.js diff --git a/modules/autoshorten.js b/modules/autoshorten.js new file mode 100644 index 0000000..7ccdb6d --- /dev/null +++ b/modules/autoshorten.js @@ -0,0 +1,30 @@ +var autoshorten = function(dbot) { + 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(urlMatches !== null) { + var url = urlMatches[0]; // Only doing one, screw you. + + var site = http.createClient(80, 'http://nc.no.de'); + var request = site.request("GET", 'mkurl', { 'host' : 'http://nc.no.de/', + 'url' + url}); + request.end(); + + request.on('response', function(response) { + dbot.say(data.channel, 'Shortened link from ' + data.user + ': ' + response.surl); + }); + + } + }, + + 'on': 'PRIVMSG' + }; +} + +exports.fetch = function(dbot) { + return autoshorten(dbot); +}; diff --git a/modules/command.js b/modules/command.js index 6f7f289..f7f5147 100644 --- a/modules/command.js +++ b/modules/command.js @@ -33,6 +33,7 @@ var command = function(dbot) { '~ignore': ignoreCommands }; }, + 'listener': function(data) { var params = data.message.split(' '); if(data.channel == dbot.name) data.channel = data.user; From eafeb23a77db9ab542bab913f7f7aeed961a4102 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 14 Apr 2012 06:08:03 +0100 Subject: [PATCH 02/33] json format fix --- modules/autoshorten.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 7ccdb6d..72d2a5d 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -11,7 +11,7 @@ var autoshorten = function(dbot) { var site = http.createClient(80, 'http://nc.no.de'); var request = site.request("GET", 'mkurl', { 'host' : 'http://nc.no.de/', - 'url' + url}); + 'url': url}); request.end(); request.on('response', function(response) { From 4bb3836665642d54511cecdbd3fbd43ac400eba2 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 14 Apr 2012 06:08:54 +0100 Subject: [PATCH 03/33] needed to require http. whoops. --- modules/autoshorten.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 72d2a5d..6f2f408 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -1,3 +1,5 @@ +var http = require('http'); + var autoshorten = function(dbot) { var dbot = dbot; From 1924d28952da14cb8ee1f4dac2bdf4f794892bf4 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 14 Apr 2012 06:12:36 +0100 Subject: [PATCH 04/33] apparently http is bad --- modules/autoshorten.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 6f2f408..6af1a8b 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -11,8 +11,8 @@ var autoshorten = function(dbot) { if(urlMatches !== null) { var url = urlMatches[0]; // Only doing one, screw you. - var site = http.createClient(80, 'http://nc.no.de'); - var request = site.request("GET", 'mkurl', { 'host' : 'http://nc.no.de/', + var site = http.createClient(80, 'nc.no.de'); + var request = site.request("GET", 'mkurl', { 'host' : 'nc.no.de/', 'url': url}); request.end(); From e1833017b05a64e0a8e5bd741cdbd18d9ed99c31 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 14 Apr 2012 06:21:38 +0100 Subject: [PATCH 05/33] i am tired --- modules/autoshorten.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 6af1a8b..1458cb5 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -10,16 +10,16 @@ var autoshorten = function(dbot) { if(urlMatches !== null) { var url = urlMatches[0]; // Only doing one, screw you. + + var options = { + 'host': 'nc.no.de', + 'port': 80, + 'path': '/mkurl?url=' + escape(url) + }; - var site = http.createClient(80, 'nc.no.de'); - var request = site.request("GET", 'mkurl', { 'host' : 'nc.no.de/', - 'url': url}); - request.end(); - - request.on('response', function(response) { + http.get(options, function(response) { dbot.say(data.channel, 'Shortened link from ' + data.user + ': ' + response.surl); }); - } }, From 7f9089bc5e311f486d5ae52d9c1f80db2861560d Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 14 Apr 2012 06:23:01 +0100 Subject: [PATCH 06/33] debug output --- modules/autoshorten.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 1458cb5..2f7b6c8 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -18,6 +18,7 @@ var autoshorten = function(dbot) { }; http.get(options, function(response) { + console.log(response); dbot.say(data.channel, 'Shortened link from ' + data.user + ': ' + response.surl); }); } From d0ed2eddd1a16f475f5af523ce1a37c0d3054285 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 14 Apr 2012 06:26:48 +0100 Subject: [PATCH 07/33] lets try this then --- modules/autoshorten.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 2f7b6c8..23e78cf 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -17,9 +17,11 @@ var autoshorten = function(dbot) { 'path': '/mkurl?url=' + escape(url) }; - http.get(options, function(response) { - console.log(response); - dbot.say(data.channel, 'Shortened link from ' + data.user + ': ' + 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); + }); }); } }, From 19a3d9cf87731e03e7f426e1e216fec744f6c998 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 14 Apr 2012 06:37:17 +0100 Subject: [PATCH 08/33] Only auto shorten long links --- modules/autoshorten.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 23e78cf..fac1ac8 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -8,7 +8,7 @@ var autoshorten = function(dbot) { var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; var urlMatches = data.message.match(urlRegex); - if(urlMatches !== null) { + if(urlMatches !== null && urlMatches[0].length > 45) { var url = urlMatches[0]; // Only doing one, screw you. var options = { From c76428b1f25075b7b1b0df6b0eae6359d8e07ea8 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 14 Apr 2012 06:41:53 +0100 Subject: [PATCH 09/33] TODO note and autoshorten in automatic loading modules --- modules/autoshorten.js | 1 + run.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index fac1ac8..ac0ac7b 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -11,6 +11,7 @@ var autoshorten = function(dbot) { if(urlMatches !== null && urlMatches[0].length > 45) { 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, diff --git a/run.js b/run.js index 7588ad5..bf81ad7 100644 --- a/run.js +++ b/run.js @@ -51,7 +51,7 @@ var DBot = function(timers) { this.server = this.config.server || 'elara.ivixor.net'; this.port = this.config.port || 6667; this.webPort = this.config.webPort || 443; - this.moduleNames = this.config.modules || [ 'command', 'js', 'admin', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'web', 'youare' ]; + this.moduleNames = this.config.modules || [ 'command', 'js', 'admin', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'web', 'youare', 'autoshorten' ]; this.language = this.config.language || 'english'; this.sessionData = {}; From ea893be393d971af26bd384d80e2d8264b2311d1 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 14 Apr 2012 12:01:52 +0100 Subject: [PATCH 10/33] change shorten length to 65 --- modules/autoshorten.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index ac0ac7b..3f5c92a 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -8,7 +8,7 @@ var autoshorten = function(dbot) { 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 > 45) { + 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. From 7680e515a81bb2828aad01af7093511fb3635c1a Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 15 Apr 2012 20:04:34 +0100 Subject: [PATCH 11/33] Remove existing ignoration functionality. --- modules/command.js | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/modules/command.js b/modules/command.js index f7f5147..fcbb291 100644 --- a/modules/command.js +++ b/modules/command.js @@ -3,57 +3,22 @@ var command = function(dbot) { var dbot = dbot; - var ignoreCommands = function (data, params) { - if(data.channel == dbot.name) data.channel = data.user; - var targetCommand = params[1]; - var ignoreMins = parseFloat(params[2]); - - if(!dbot.sessionData.hasOwnProperty("ignoreCommands")) { - dbot.sessionData.ignoreCommands = {}; - } - if(!dbot.sessionData.ignoreCommands.hasOwnProperty(targetCommand)) { - dbot.sessionData.ignoreCommands[targetCommand] = []; - } - - if(dbot.sessionData.ignoreCommands[targetCommand].include(data.channel)) { - dbot.say(data.channel, "Already ignoring '" + targetCommand + "' in '" + data.channel + "'."); - } else { - dbot.sessionData.ignoreCommands[targetCommand].push(data.channel); - dbot.timers.addOnceTimer(ignoreMins * 60 * 1000, function() { - dbot.sessionData.ignoreCommands[targetCommand].splice(dbot.sessionData.ignoreCommands[targetCommand].indexOf(data.channel), 1); - dbot.say(data.channel, "No longer ignoring '" + targetCommand + "' in '" + data.channel + "'."); - }); - dbot.say(data.channel, "Ignoring '" + targetCommand + "' in '" + data.channel + "' for the next " + ignoreMins + " minute" + (ignoreMins == 1 ? "" : "s") + "."); - } - }; - return { 'onLoad': function() { return { - '~ignore': ignoreCommands + '~ignore': null }; }, 'listener': function(data) { var params = data.message.split(' '); if(data.channel == dbot.name) data.channel = data.user; - - var ignoringCommand = false; - if(dbot.sessionData.hasOwnProperty("ignoreCommands")) { - if(dbot.sessionData.ignoreCommands.hasOwnProperty(params[0])) { - if(dbot.sessionData.ignoreCommands[params[0]].include(data.channel)) { - ignoringCommand = true; - } - } - } - + if(dbot.commands.hasOwnProperty(params[0])) { if((dbot.db.bans.hasOwnProperty(params[0]) && dbot.db.bans[params[0]].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(ignoringCommand) { - // do nothing, this stops us falling through to the non-command stuff } else { dbot.commands[params[0]](data, params); dbot.save(); From 0ecca6ae9897d46f3d068a85acbab102c24aaaeb Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 15 Apr 2012 20:42:23 +0100 Subject: [PATCH 12/33] change module loading so there's only one loop through the moduels --- run.js | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/run.js b/run.js index bf81ad7..9909a37 100644 --- a/run.js +++ b/run.js @@ -39,6 +39,9 @@ var DBot = function(timers) { if(!this.db.hasOwnProperty("locks")) { this.db.locks = []; } + if(!this.db.hasOwnProperty("ignores")) { + this.db.locks = {}; + } // Load the strings file this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); @@ -97,6 +100,7 @@ DBot.prototype.reloadModules = function() { this.rawModules = []; this.modules = []; this.commands = {}; + this.commandMap = {}; // Map of which commands belong to which modules this.timers.clearTimers(); this.save(); @@ -111,36 +115,34 @@ DBot.prototype.reloadModules = function() { delete require.cache[path]; require('./snippets'); + this.instance.removeListeners(); + this.moduleNames.each(function(name) { var cacheKey = require.resolve('./modules/' + name); delete require.cache[cacheKey]; try { - this.rawModules.push(require('./modules/' + name)); + var rawModule = require('./modules/' + name); + var module = rawModule.fetch(this); + this.rawModules.push(rawModule); + + if(module.listener) { + this.instance.addListener(module.on, module.listener); + } + + if(module.onLoad) { + var newCommands = module.onLoad(); + for(key in newCommands) { + if(newCommands.hasOwnProperty(key) && Object.prototype.isFunction(newCommands[key])) { + this.commands[key] = newCommands[key]; + } + } + } + + this.modules.push(module); } catch(err) { console.log(this.strings[this.language].module_load_error.format({'moduleName': name})); } }.bind(this)); - - this.instance.removeListeners(); - - this.modules = this.rawModules.collect(function(rawModule) { - var module = rawModule.fetch(this); - - if(module.listener) { - this.instance.addListener(module.on, module.listener); - } - - if(module.onLoad) { - var newCommands = module.onLoad(); - for(key in newCommands) { - if(newCommands.hasOwnProperty(key) && Object.prototype.isFunction(newCommands[key])) { - this.commands[key] = newCommands[key]; - } - } - } - - return module; - }.bind(this)); }; DBot.prototype.cleanNick = function(key) { From b232103178d41feacf8b60e9304476d9c1fe61b6 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 15 Apr 2012 20:46:42 +0100 Subject: [PATCH 13/33] Create command map describing which commands belong to which module. --- run.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/run.js b/run.js index 9909a37..02d7ad1 100644 --- a/run.js +++ b/run.js @@ -120,10 +120,12 @@ DBot.prototype.reloadModules = function() { this.moduleNames.each(function(name) { var cacheKey = require.resolve('./modules/' + name); delete require.cache[cacheKey]; + try { var rawModule = require('./modules/' + name); var module = rawModule.fetch(this); this.rawModules.push(rawModule); + this.commandMap[name] = []; if(module.listener) { this.instance.addListener(module.on, module.listener); @@ -134,6 +136,7 @@ DBot.prototype.reloadModules = function() { for(key in newCommands) { if(newCommands.hasOwnProperty(key) && Object.prototype.isFunction(newCommands[key])) { this.commands[key] = newCommands[key]; + this.commandMap[name].push(key); } } } From 0062dde196283e0614f0077d84b75b5885ea67be Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 15 Apr 2012 21:43:02 +0100 Subject: [PATCH 14/33] Command map changed round the other way. Modules have name and ignorable properties. Ignore and unignore commands, which currently effect actual commands but not listeners yet. --- modules/admin.js | 6 +++- modules/autoshorten.js | 6 +++- modules/command.js | 80 +++++++++++++++++++++++++++++++++++++++--- modules/dice.js | 6 +++- modules/drama.js | 6 +++- modules/js.js | 6 +++- modules/kick.js | 5 ++- modules/modehate.js | 6 +++- modules/puns.js | 6 +++- modules/quotes.js | 6 +++- modules/spelling.js | 6 +++- modules/web.js | 6 +++- modules/youare.js | 6 +++- run.js | 5 ++- 14 files changed, 137 insertions(+), 19 deletions(-) diff --git a/modules/admin.js b/modules/admin.js index d20a488..7c5962f 100644 --- a/modules/admin.js +++ b/modules/admin.js @@ -134,7 +134,11 @@ var adminCommands = function(dbot) { } }, - 'on': 'PRIVMSG' + 'on': 'PRIVMSG', + + 'name': 'admin', + + 'ignorable': false }; }; diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 3f5c92a..eb0cf7c 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -27,7 +27,11 @@ var autoshorten = function(dbot) { } }, - 'on': 'PRIVMSG' + 'on': 'PRIVMSG', + + 'name': 'autoshorten', + + 'ignorable': true }; } diff --git a/modules/command.js b/modules/command.js index fcbb291..55b3168 100644 --- a/modules/command.js +++ b/modules/command.js @@ -6,7 +6,69 @@ var command = function(dbot) { return { 'onLoad': function() { return { - '~ignore': null + '~ignore': function(data, params) { + var ignorableModules = []; + for(var i=0;i Date: Sun, 15 Apr 2012 22:04:58 +0100 Subject: [PATCH 15/33] Added ignore checkers to all ignorable modules with listeners, bit messy but eh. --- modules/autoshorten.js | 38 +++++++++++++++++++++----------------- modules/puns.js | 16 ++++++++++------ modules/quotes.js | 40 ++++++++++++++++++++++------------------ modules/spelling.js | 36 ++++++++++++++++++++---------------- modules/youare.js | 13 +++++++++---- 5 files changed, 82 insertions(+), 61 deletions(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index eb0cf7c..0598ce9 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -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 }; diff --git a/modules/puns.js b/modules/puns.js index 675f92c..0aa27dc 100644 --- a/modules/puns.js +++ b/modules/puns.js @@ -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 }; diff --git a/modules/quotes.js b/modules/quotes.js index fdbf6d3..50f2921 100644 --- a/modules/quotes.js +++ b/modules/quotes.js @@ -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 }; diff --git a/modules/spelling.js b/modules/spelling.js index bfd1c77..8fed950 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -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 } diff --git a/modules/youare.js b/modules/youare.js index 7152f3d..2321a39 100644 --- a/modules/youare.js +++ b/modules/youare.js @@ -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 }; From 8f5759252f5617f7a737b3ef680755218e065d0c Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 15 Apr 2012 22:15:10 +0100 Subject: [PATCH 16/33] name, not names --- modules/puns.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/puns.js b/modules/puns.js index 0aa27dc..23a6115 100644 --- a/modules/puns.js +++ b/modules/puns.js @@ -1,5 +1,5 @@ var puns = function(dbot) { - var names = 'puns'; + var name = 'puns'; var dbot = dbot; return { From 79cf8243a0d37177c52e120854554a2690da4c20 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 15 Apr 2012 23:26:14 +0100 Subject: [PATCH 17/33] quotes ignore check for ~quotecat --- modules/command.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/command.js b/modules/command.js index 55b3168..a66b12e 100644 --- a/modules/command.js +++ b/modules/command.js @@ -100,7 +100,9 @@ var command = function(dbot) { } else { q[1] = q[1].trim(); key = dbot.cleanNick(q[1]) - if(dbot.db.quoteArrs.hasOwnProperty(key) && dbot.moduleNames.include('quotes')) { + if(dbot.db.quoteArrs.hasOwnProperty(key) && dbot.moduleNames.include('quotes') && + (dbot.db.ignores.hasOwnProperty(data.user) && + dbot.db.ignores[data.user].include(name)) == false) { var params = ['~q']; key.split(' ').each((function(word) { this.push(word); From 27f5ab6f303fab1d308b44b084c640bfb41f070b Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 15 Apr 2012 23:27:14 +0100 Subject: [PATCH 18/33] quotes not name. jesus. --- modules/command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/command.js b/modules/command.js index a66b12e..a97eed2 100644 --- a/modules/command.js +++ b/modules/command.js @@ -102,7 +102,7 @@ var command = function(dbot) { key = dbot.cleanNick(q[1]) if(dbot.db.quoteArrs.hasOwnProperty(key) && dbot.moduleNames.include('quotes') && (dbot.db.ignores.hasOwnProperty(data.user) && - dbot.db.ignores[data.user].include(name)) == false) { + dbot.db.ignores[data.user].include('quotes')) == false) { var params = ['~q']; key.split(' ').each((function(word) { this.push(word); From 1b0a32078c4cf669c8cff7f1b89c6abc0b6e51be Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 15 Apr 2012 23:51:30 +0100 Subject: [PATCH 19/33] remove redundant hasownproperty check from puns since ~q already does that --- modules/puns.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/puns.js b/modules/puns.js index 23a6115..0696866 100644 --- a/modules/puns.js +++ b/modules/puns.js @@ -7,11 +7,9 @@ var puns = function(dbot) { 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); - } + data.message = '~q ' + data.user.toLowerCase(); + var params = data.message.split(' '); + dbot.commands[params[0]](data, params); } } }, From 39d3021870cefc350d1a72241ce2cbfd4662fd7d Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Mon, 16 Apr 2012 00:23:13 +0100 Subject: [PATCH 20/33] autoshorten threshold 80 --- modules/autoshorten.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 0598ce9..02be309 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -11,7 +11,7 @@ var autoshorten = function(dbot) { 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 > 80) { var url = urlMatches[0]; // Only doing one, screw you. // TODO: Make this use a decent URL shortener. Mine is shit. From eb9b9018bf0a10519d729d8114bb25c86c823f3e Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Mon, 16 Apr 2012 15:23:19 +0100 Subject: [PATCH 21/33] add check in puns again derp --- modules/puns.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/puns.js b/modules/puns.js index 0696866..a7cc3aa 100644 --- a/modules/puns.js +++ b/modules/puns.js @@ -6,7 +6,8 @@ var puns = function(dbot) { 'listener': function(data) { if((dbot.db.ignores.hasOwnProperty(data.user) && dbot.db.ignores[data.user].include(name)) == false) { - if(dbot.moduleNames.include('quotes')) { + if(dbot.moduleNames.include('quotes') && + dbot.db.quotes.hasOwnProperty(data.user)) { data.message = '~q ' + data.user.toLowerCase(); var params = data.message.split(' '); dbot.commands[params[0]](data, params); From 9be6d5beaa2e631998660dbbe9d64971be2ce405 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Thu, 19 Apr 2012 12:01:06 +0100 Subject: [PATCH 22/33] experimental badwords stuff --- modules/badwords.js | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 modules/badwords.js diff --git a/modules/badwords.js b/modules/badwords.js new file mode 100644 index 0000000..af8f326 --- /dev/null +++ b/modules/badwords.js @@ -0,0 +1,53 @@ +// Find which badwords are currently enacted in the current channel +var badwords = function(dbot) { + var name = 'badwords'; + var dbot = dbot; + var badWordLock = false; + + var commands = { + '~badwords': function(data, params) { + if(badWordLock == true) { + dbot.say('reality', 'Another badwords query is in action. Try again in a few seconds.'); + } else { + data.channel = '#42'; + badWordLock = true; + + dbot.db.sessionData.badwords.finished = false; + + dbot.say('bots', 'badwords ' + data.channel + ' list'); + dbot.instance.addListener('PRIVMSG', function(data) { + if(data.channel === 'bots') { + if(data.message.indexOf('bad words list is empty') != -1) { + dbot.db.sessionData.badwords.count = 0; + dbot.db.sessionData.badwords.finished = true; + } else { + var wordMatch = data.message.valMatch(/\w([1-10])\w(.*)/, 2); + dbot.say('reality', wordMatch[1]); + } + } + }); + + dbot.db.sessionData.badwords = {}; + badWordLock = false; + } + } + }; + + return { + 'onLoad': function(data) { + if(dbot.db.sessionData.hasOwnProperty('badwords')) { + dbot.db.sessionData.badwords = {}; + } + + return commands; + }, + + 'name': name, + + 'ignorable': true + }; +} + +exports.fetch = function(dbot) { + return puns(dbot); +}; From fc5043e310798001f8bdcdc139010d16a6e89884 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Thu, 19 Apr 2012 12:02:27 +0100 Subject: [PATCH 23/33] experimental badwords stuff --- modules/badwords.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/badwords.js b/modules/badwords.js index af8f326..bd16699 100644 --- a/modules/badwords.js +++ b/modules/badwords.js @@ -49,5 +49,5 @@ var badwords = function(dbot) { } exports.fetch = function(dbot) { - return puns(dbot); + return badwords(dbot); }; From b6607f7cd6ee4ffe0d616fd1ff32cef538c26616 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Thu, 19 Apr 2012 12:09:14 +0100 Subject: [PATCH 24/33] quoteArrs, not quotes... jesus reality --- modules/puns.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/puns.js b/modules/puns.js index a7cc3aa..e0b7176 100644 --- a/modules/puns.js +++ b/modules/puns.js @@ -7,7 +7,7 @@ var puns = function(dbot) { if((dbot.db.ignores.hasOwnProperty(data.user) && dbot.db.ignores[data.user].include(name)) == false) { if(dbot.moduleNames.include('quotes') && - dbot.db.quotes.hasOwnProperty(data.user)) { + dbot.db.quoteArrs.hasOwnProperty(data.user)) { data.message = '~q ' + data.user.toLowerCase(); var params = data.message.split(' '); dbot.commands[params[0]](data, params); From b2ede3f5d562b940158438481abbde359bb4a60f Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Thu, 19 Apr 2012 12:14:08 +0100 Subject: [PATCH 25/33] print the error to console if it fails to load a module --- modules/badwords.js | 2 +- run.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/badwords.js b/modules/badwords.js index bd16699..2e7ac29 100644 --- a/modules/badwords.js +++ b/modules/badwords.js @@ -46,7 +46,7 @@ var badwords = function(dbot) { 'ignorable': true }; -} +}; exports.fetch = function(dbot) { return badwords(dbot); diff --git a/run.js b/run.js index 9b78ef6..d8e93a7 100644 --- a/run.js +++ b/run.js @@ -143,6 +143,7 @@ DBot.prototype.reloadModules = function() { this.modules.push(module); } catch(err) { console.log(this.strings[this.language].module_load_error.format({'moduleName': name})); + console.log(err); } }.bind(this)); }; From eb683369f2da780cab83b0a3e9269f40f3c18006 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Thu, 19 Apr 2012 12:19:09 +0100 Subject: [PATCH 26/33] onLoad has no data argument --- modules/badwords.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/badwords.js b/modules/badwords.js index 2e7ac29..5ed3615 100644 --- a/modules/badwords.js +++ b/modules/badwords.js @@ -34,7 +34,7 @@ var badwords = function(dbot) { }; return { - 'onLoad': function(data) { + 'onLoad': function() { if(dbot.db.sessionData.hasOwnProperty('badwords')) { dbot.db.sessionData.badwords = {}; } From 27d5c1aa61ac41b70a41fb7c6232d274ecab8794 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Thu, 19 Apr 2012 12:20:57 +0100 Subject: [PATCH 27/33] Right, sessionData isn't in the DB. --- modules/badwords.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/badwords.js b/modules/badwords.js index 5ed3615..48c3325 100644 --- a/modules/badwords.js +++ b/modules/badwords.js @@ -12,14 +12,14 @@ var badwords = function(dbot) { data.channel = '#42'; badWordLock = true; - dbot.db.sessionData.badwords.finished = false; + dbot.sessionData.badwords.finished = false; dbot.say('bots', 'badwords ' + data.channel + ' list'); dbot.instance.addListener('PRIVMSG', function(data) { if(data.channel === 'bots') { if(data.message.indexOf('bad words list is empty') != -1) { - dbot.db.sessionData.badwords.count = 0; - dbot.db.sessionData.badwords.finished = true; + dbot.sessionData.badwords.count = 0; + dbot.sessionData.badwords.finished = true; } else { var wordMatch = data.message.valMatch(/\w([1-10])\w(.*)/, 2); dbot.say('reality', wordMatch[1]); @@ -27,7 +27,7 @@ var badwords = function(dbot) { } }); - dbot.db.sessionData.badwords = {}; + dbot.sessionData.badwords = {}; badWordLock = false; } } @@ -35,8 +35,8 @@ var badwords = function(dbot) { return { 'onLoad': function() { - if(dbot.db.sessionData.hasOwnProperty('badwords')) { - dbot.db.sessionData.badwords = {}; + if(dbot.sessionData.hasOwnProperty('badwords')) { + dbot.sessionData.badwords = {}; } return commands; From 573f1fb6ea106cd078156b7cb9e82cac2566b67c Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Thu, 19 Apr 2012 12:22:04 +0100 Subject: [PATCH 28/33] create sessiondata entry if it doesn't exist --- modules/badwords.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/badwords.js b/modules/badwords.js index 48c3325..8d7ab8c 100644 --- a/modules/badwords.js +++ b/modules/badwords.js @@ -35,7 +35,7 @@ var badwords = function(dbot) { return { 'onLoad': function() { - if(dbot.sessionData.hasOwnProperty('badwords')) { + if(!dbot.sessionData.hasOwnProperty('badwords')) { dbot.sessionData.badwords = {}; } From 2954df3a52e656bf532721f43dcf2a09a1b3b2a6 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Thu, 19 Apr 2012 20:55:15 +0100 Subject: [PATCH 29/33] ru puns through cleannicks --- modules/puns.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/puns.js b/modules/puns.js index e0b7176..ebe5b5d 100644 --- a/modules/puns.js +++ b/modules/puns.js @@ -4,6 +4,8 @@ var puns = function(dbot) { return { 'listener': function(data) { + data.user = dbot.cleanNick(data.user); + if((dbot.db.ignores.hasOwnProperty(data.user) && dbot.db.ignores[data.user].include(name)) == false) { if(dbot.moduleNames.include('quotes') && From 64fd389418b3cabd08287e8a99082fd8d1763826 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Fri, 20 Apr 2012 13:48:12 +0100 Subject: [PATCH 30/33] badwords changes --- modules/badwords.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/modules/badwords.js b/modules/badwords.js index 8d7ab8c..d53dab0 100644 --- a/modules/badwords.js +++ b/modules/badwords.js @@ -12,21 +12,10 @@ var badwords = function(dbot) { data.channel = '#42'; badWordLock = true; - dbot.sessionData.badwords.finished = false; + dbot.sessionData.badwords.waiting = true; dbot.say('bots', 'badwords ' + data.channel + ' list'); - dbot.instance.addListener('PRIVMSG', function(data) { - if(data.channel === 'bots') { - if(data.message.indexOf('bad words list is empty') != -1) { - dbot.sessionData.badwords.count = 0; - dbot.sessionData.badwords.finished = true; - } else { - var wordMatch = data.message.valMatch(/\w([1-10])\w(.*)/, 2); - dbot.say('reality', wordMatch[1]); - } - } - }); - + dbot.instance.addListener('PRIVMSG', dbot.sessionData.badwords = {}; badWordLock = false; } @@ -42,6 +31,20 @@ var badwords = function(dbot) { return commands; }, + 'listener': function(data) { + if(data.channel === 'bots') { + if(data.message.indexOf('bad words list is empty') != -1) { + dbot.sessionData.badwords.count = 0; + dbot.sessionData.badwords.finished = true; + } else { + var wordMatch = data.message.valMatch(/\w([1-10])\w(.*)/, 2); + dbot.say('reality', wordMatch[1]); + } + } + }, + + 'on': 'PRIVMSG', + 'name': name, 'ignorable': true From 42c4871a16234517be3dd7ac6186e6ef3c6797d3 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 19 May 2012 16:33:31 +0100 Subject: [PATCH 31/33] Switched key of strings object so that there's only one object and it's easier to read and therefore translate. Created 't' function to translate strings, changed quotes module to this format. Need to change the others. Will now fall back to English if translation in given language is not available. --- modules/quotes.js | 63 +++++++------- run.js | 10 +++ strings.json | 210 ++++++++++++++++++++++++++++++---------------- 3 files changed, 182 insertions(+), 101 deletions(-) diff --git a/modules/quotes.js b/modules/quotes.js index 50f2921..4cd21cc 100644 --- a/modules/quotes.js +++ b/modules/quotes.js @@ -54,7 +54,7 @@ var quotes = function(dbot) { if(quotes.hasOwnProperty(key)) { dbot.say(data.channel, q[1] + ': ' + interpolatedQuote(key)); } else { - dbot.say(data.channel, dbot.strings[dbot.language].category_not_found.format({'category': q[1]})); + dbot.say(data.channel, dbot.t('category_not_found', {'category': q[1]})); } } }, @@ -71,7 +71,7 @@ var quotes = function(dbot) { qSizes = qSizes.sort(function(a, b) { return a[1] - b[1]; }); qSizes = qSizes.slice(qSizes.length - 10).reverse(); - var qString = dbot.strings[dbot.language].large_categories; + var qString = dbot.t('large_categories'); for(var i=0;i 0) { - dbot.say(data.channel, dbot.strings[dbot.language].prune.format({'categories': pruned.join(", ")})); + dbot.say(data.channel, dbot.t('prune', {'categories': pruned.join(", ")})); } else { - dbot.say(data.channel, dbot.strings[dbot.language].no_prune); + dbot.say(data.channel, dbot.t('no_prune')); } } }; @@ -289,7 +290,7 @@ var quotes = function(dbot) { 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.'); + dbot.say(data.channel, dbot.t('command_ban', {'user': data.user})); } else { if(!dbot.db.quoteArrs.hasOwnProperty('realityonce')) { dbot.db.quoteArrs['realityonce'] = []; diff --git a/run.js b/run.js index d8e93a7..76935bb 100644 --- a/run.js +++ b/run.js @@ -78,6 +78,16 @@ DBot.prototype.say = function(channel, data) { this.instance.say(channel, data); }; +// Format given stored string in config language +DBot.prototype.t = function(string, formatData) { + var lang = this.language; + if(!this.strings[string].hasOwnProperty(lang)) { + lang = "english"; + } + + return this.strings[string][lang].format(formatData); +}; + DBot.prototype.act = function(channel, data) { this.instance.send('PRIVMSG', channel, ':\001ACTION ' + data + '\001'); } diff --git a/strings.json b/strings.json index 745289f..a10d315 100644 --- a/strings.json +++ b/strings.json @@ -1,74 +1,144 @@ { - "english": { - "syntax_error": "Invalid syntax. Initiate incineration.", - "module_load_error": "Failed to load module: {moduleName}", - "category_not_found": "Nobody loves {category}", - "large_categories": "Largest categories: ", - "empty_category": "That category has no quotes in. Commence incineration.", - "no_results": "No results found.", - "locked_category": "{category} is locked. Commence incineration.", - "no_quotes": "No quotes exist under {category}", - "last_removed": "Last quote removed from {category}.", - "no_recent_adds": "No quotes were added recently.", - "rmlast_spam": "No spamming that shit. Try again in a few minutes...", - "removed_from": "'{quote}' removed from {category}", - "q_not_exist_under": "'{quote}' doesn't exist under '{category}'.", - "total_quotes": "Total quote count: {count}.", - "quote_exists": "Quote already in DB. Initiate incineration.", - "quote_saved": "Quote saved in '{category}' ({count}).", - "quote_replace": "No replacing arrays, you whore.", - "prune": "Pruning empty quote categories: {categories}", - "no_prune": "No empty quote categories. Commence incineration.", - "command_ban": " is banned from using this command. Commence incineration.", - "correction": "Did you mean: ", - "gpull": "Git pulled that shit.", - "reload": "Reloaded that shit.", - "load_module": "Loaded new module: {moduleName}", - "unload_module": "Turned off module: {moduleName}", - "unload_error": "{moduleName} isn't loaded. Idiot.", - "banned": "{user} banned from {command}", - "unbanned": "{user} unbanned from {command}", - "unban_error": "{user} wasn't banned from that command, fool.", - "modehate": "Hating on {user}", - "unmodehate": "No longer hating on {user}", - "qlock": "Locked quote category: {category}", - "spelling_self": "{correcter} meant: {fix}", - "spelling_other": "{correcter} thinks {candidate} meant: {fix}" + "syntax_error": { + "english": "Invalid syntax. Initiate incineration.", + "spanish": "Sintaxis no válida. Iniciar incineración." }, - "spanish": { - "syntax_error": "Sintaxis no válida. Iniciar incineración.", - "module_load_error": "No se pudó cargar el módulo: {moduleName}", - "category_not_found": "Nadie ama a {category}", - "large_categories": "Los categorías más grandes: ", - "empty_category": "Categoría vacía. Iniciar incineración.", - "no_results": "No hubo ningún resultado.", - "locked_category": "{category} está cerrada. Comenzar incineración.", - "no_quotes": "Ninguna cita existe en {category}", - "last_removed": "Última cita quitado de {category}.", - "no_recent_adds": "Ninguna cita fue añadido recientamente.", - "rmlast_spam": "No me inundes de mierda. Intenta otra vez en unos minutos.", - "removed_from": "'{quote}' quitado de {category}", - "q_not_exist_under": "'{quote}' no existe en '{category}'.", - "total_quotes": "Total de citas: {count}.", - "quote_exists": "Cita ya existe. Iniciar incineración.", - "quote_saved": "Cita guardada en '{category}' ({count})", - "quote_replace": "No sustituites arrays, hijo de puta.", - "prune": "Reduciendo categorías vacías {categories}", - "no_prune": "Ninguna categoría vacía. Comenzar incineracíon", - "command_ban": " está prohibido de usar esta instrucción. Comenzar incineración.", - "correction": "¿Querías decir: ", - "gpull": "Hecho git pull en esta mierda.", - "reload": "Recargado esta mierda.", - "load_module": "Cargado módulo nuevo: {moduleName}", - "unload_module": "Descargado modulo: {moduleName}", - "unload_error": "{moduleName} no está cargado. Idiota.", - "banned": "{user} está prohibido de usar {command}", - "unbanned": "{user} no está prohibido de user {command}", - "unban_error": "{user} no fue prohibido de esta instrucción, tont@..", - "modehate": "Odiando a {user}", - "unmodehate": "Ni siquera odiando a {user}", - "qlock": "Cerrado la categoría: {category}", - "spelling_self": "{correcter} quería decir: {fix}", - "spelling_other": "{correcter} piensa que {candidate} queria decir: {fix}" + "module_load_error": { + "english": "Failed to load module: {moduleName}", + "spanish": "No se pudó cargar el módulo: {moduleName}" + }, + "category_not_found": { + "english": "Nobody loves {category}", + "spanish": "Nadie ama a {category}" + }, + "large_categories": { + "english": "Largest categories: ", + "spanish": "Los categorías más grandes: " + }, + "empty_category": { + "english": "That category has no quotes in. Commence incineration.", + "spanish": "Categoría vacía. Iniciar incineración." + }, + "no_results": { + "english": "No results found.", + "spanish": "No hubo ningún resultado." + }, + "locked_category": { + "english": "{category} is locked. Commence incineration.", + "spanish": "{category} está cerrada. Comenzar incineración." + }, + "no_quotes": { + "english": "No quotes exist under {category}", + "spanish": "Ninguna cita existe en {category}" + }, + "last_removed": { + "english": "Last quote removed from {category}.", + "spanish": "Última cita quitado de {category}." + }, + "no_recent_adds": { + "english": "No quotes were added recently.", + "spanish": "Ninguna cita fue añadido recientamente." + }, + "rmlast_spam": { + "english": "No spamming that shit. Try again in a few minutes...", + "spanish": "No me inundes de mierda. Intenta otra vez en unos minutos." + }, + "removed_from": { + "english": "'{quote}' removed from {category}", + "spanish": "'{quote}' quitado de {category}" + }, + "q_not_exist_under": { + "english": "'{quote}' doesn't exist under '{category}'.", + "spanish": "'{quote}' no existe en '{category}'." + }, + "total_quotes": { + "english": "Total quote count: {count}.", + "spanish": "Total de citas: {count}." + }, + "quote_exists": { + "english": "Quote already in DB. Initiate incineration.", + "spanish": "Cita ya existe. Iniciar incineración." + }, + "quote_saved": { + "english": "Quote saved in '{category}' ({count}).", + "spanish": "Cita guardada en '{category}' ({count})" + }, + "quote_replace": { + "english": "No replacing arrays, you whore.", + "spanish": "No sustituites arrays, hijo de puta." + }, + "quote_count": { + "english": "{category} has {count} quotes." + }, + "prune": { + "english": "Pruning empty quote categories: {categories}", + "spanish": "Reduciendo categorías vacías {categories}" + }, + "no_prune": { + "english": "No empty quote categories. Commence incineration.", + "spanish": "Ninguna categoría vacía. Comenzar incineracíon" + }, + "command_ban": { + "english": "{user} is banned from using this command. Commence incineration.", + "spanish": "{user} está prohibido de usar esta instrucción. Comenzar incineración." + }, + "correction": { + "english": "Did you mean: ", + "spanish": "¿Querías decir: " + }, + "gpull": { + "english": "Git pulled that shit.", + "spanish": "Hecho git pull en esta mierda." + }, + "reload": { + "english": "Reloaded that shit.", + "spanish": "Recargado esta mierda." + }, + "load_module": { + "english": "Loaded new module: {moduleName}", + "spanish": "Cargado módulo nuevo: {moduleName}" + }, + "unload_module": { + "english": "Turned off module: {moduleName}", + "spanish": "Descargado modulo: {moduleName}" + }, + "unload_error": { + "english": "{moduleName} isn't loaded. Idiot.", + "spanish": "{moduleName} no está cargado. Idiota." + }, + "banned": { + "english": "{user} banned from {command}", + "spanish": "{user} está prohibido de usar {command}" + }, + "unbanned": { + "english": "{user} unbanned from {command}", + "spanish": "{user} no está prohibido de user {command}" + }, + "unban_error": { + "english": "{user} wasn't banned from that command, fool.", + "spanish": "{user} no fue prohibido de esta instrucción, tont.." + }, + "modehate": { + "english": "Hating on {user}", + "spanish": "Odiando a {user}" + }, + "unmodehate": { + "english": "No longer hating on {user}", + "spanish": "Ni siquera odiando a {user}" + }, + "qlock": { + "english": "Locked quote category: {category}", + "spanish": "Cerrado la categoría: {category}" + }, + "spelling_self": { + "english": "{correcter} meant: {fix}", + "spanish": "{correcter} quería decir: {fix}" + }, + "spelling_other": { + "english": "{correcter} thinks {candidate} meant: {fix}", + "spanish": "{correcter} piensa que {candidate} queria decir: {fix}" + }, + "quote_link": { + "english": "Link to {category}" } } From fa2d0b8465ffca5fc1470ebdc9a37786367d50d7 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 19 May 2012 16:48:01 +0100 Subject: [PATCH 32/33] Converted all of the other modules to the new translate syntax. --- modules/admin.js | 22 +++++++++++----------- modules/command.js | 6 ++---- modules/spelling.js | 4 ++-- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/modules/admin.js b/modules/admin.js index 7c5962f..36e3c1e 100644 --- a/modules/admin.js +++ b/modules/admin.js @@ -25,7 +25,7 @@ var adminCommands = function(dbot) { child = exec("git pull", function (error, stdout, stderr) { console.log(stderr); - dbot.say(data.channel, dbot.strings[dbot.language].gpull); + dbot.say(data.channel, dbot.t('gpull')); commands.reload(data, params); }.bind(this)); }, @@ -34,7 +34,7 @@ var adminCommands = function(dbot) { dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); dbot.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); dbot.reloadModules(); - dbot.say(data.channel, dbot.strings[dbot.language].reload); + dbot.say(data.channel, dbot.t('reload')); }, 'say': function(data, params) { @@ -60,7 +60,7 @@ var adminCommands = function(dbot) { 'load': function(data, params) { dbot.moduleNames.push(params[1]); dbot.reloadModules(); - dbot.say(data.channel, dbot.strings[dbot.language].load_module.format({'moduleName': params[1]})); + dbot.say(data.channel, dbot.t('load_module', {'moduleName': params[1]})); }, 'unload': function(data, params) { @@ -72,9 +72,9 @@ var adminCommands = function(dbot) { dbot.moduleNames.splice(moduleIndex, 1); dbot.reloadModules(); - dbot.say(data.channel, dbot.strings[dbot.language].unload_module.format({'moduleName': params[1]})); + dbot.say(data.channel, dbot.t('unload_module', {'moduleName': params[1]})); } else { - dbot.say(data.channel, dbot.strings[dbot.language].unload_error.format({'moduleName': params[1]})); + dbot.say(data.channel, dbot.t('unload_error', {'moduleName': params[1]})); } }, @@ -84,31 +84,31 @@ var adminCommands = function(dbot) { } else { dbot.db.bans[params[2]] = [ params[1] ]; } - dbot.say(data.channel, dbot.strings[dbot.language].banned.format({'user': params[1], 'command': params[2]})); + dbot.say(data.channel, dbot.t('banned', {'user': params[1], 'command': params[2]})); }, 'unban': function(data, params) { if(dbot.db.bans.hasOwnProperty(params[2]) && dbot.db.bans[params[2]].include(params[1])) { dbot.db.bans[params[2]].splice(dbot.db.bans[params[2]].indexOf(params[1]), 1); - dbot.say(data.channel, dbot.strings[dbot.language].unbanned.format({'user': params[1], 'command': params[2]})); + dbot.say(data.channel, dbot.t('unbanned', {'user': params[1], 'command': params[2]})); } else { - dbot.say(data.channel, dbot.strings[dbot.language].unban_error.format({'user': params[1]})); + dbot.say(data.channel, dbot.t('unban_error', {'user': params[1]})); } }, 'modehate': function(data, params) { dbot.db.modehate.push(params[1]); - dbot.say(data.channel, dbot.strings[dbot.language].modehate.format({'user': params[1]})); + dbot.say(data.channel, dbot.t('modehate', {'user': params[1]})); }, 'unmodehate': function(data, params) { dbot.db.modehate.splice(dbot.db.modehate.indexOf(params[1]), 1); - dbot.say(data.channel, dbot.strings[dbot.language].unmodehate.format({'user': params[1]})); + dbot.say(data.channel, dbot.t('unmodehate', {'user': params[1]})); }, 'lock': function(data, params) { dbot.db.locks.push(params[1]); - dbot.say(data.channel, dbot.strings[dbot.language].qlock.format({'category': params[1]})); + dbot.say(data.channel, dbot.t('qlock', {'category': params[1]})); } }; diff --git a/modules/command.js b/modules/command.js index a97eed2..b23f25a 100644 --- a/modules/command.js +++ b/modules/command.js @@ -79,8 +79,7 @@ var command = function(dbot) { if(dbot.commands.hasOwnProperty(params[0])) { if((dbot.db.bans.hasOwnProperty(params[0]) && dbot.db.bans[params[0]].include(data.user)) || dbot.db.bans['*'].include(data.user)) { - dbot.say(data.channel, data.user + - ' is banned from using this command. Commence incineration.'); + dbot.say(data.channel, dbot.t('command_ban', {'user': data.user})); } else { var commandBelongsTo = dbot.commandMap[params[0]]; if(dbot.db.ignores.hasOwnProperty(data.user) && @@ -95,8 +94,7 @@ var command = function(dbot) { var q = data.message.valMatch(/^~([\d\w\s-]*)/, 2); if(q) { if(dbot.db.bans['*'].include(data.user)) { - dbot.say(data.channel, data.user + - ' is banned from using this command. Commence incineration.'); + dbot.say(data.channel, dbot.t('command_ban', {'user': data.user})); } else { q[1] = q[1].trim(); key = dbot.cleanNick(q[1]) diff --git a/modules/spelling.js b/modules/spelling.js index 8fed950..37f3d51 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -45,11 +45,11 @@ var spelling = function(dbot) { 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)); + dbot.say(data.channel, dbot.t('spelling_self', 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)); + dbot.say(data.channel, dbot.t('spelling_other', e)); }); } else { if(last.hasOwnProperty(data.channel)) { From 059768592a5a57262262cbcf3d35abc37cec81d9 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sat, 19 May 2012 17:36:21 +0100 Subject: [PATCH 33/33] Changed most of the English output strings to formatted strings. --- modules/autoshorten.js | 2 +- modules/command.js | 36 ++++++++++-------------------------- modules/kick.js | 8 +++++--- strings.json | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index 02be309..ff4fc90 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -24,7 +24,7 @@ var autoshorten = function(dbot) { 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); + dbot.say(data.channel, dbot.t('shorten_link', {'user': data.user}) + JSON.parse(response).surl); }); }); } diff --git a/modules/command.js b/modules/command.js index b23f25a..1da6b65 100644 --- a/modules/command.js +++ b/modules/command.js @@ -14,14 +14,9 @@ var command = function(dbot) { } } - var usageString = 'Usage: ~ignore [module]. Modules you can ignore are: '; - for(var i=0;i