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/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/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 diff --git a/modules/command.js b/modules/command.js index a97eed2..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 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/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)) { diff --git a/run.js b/run.js index 6b02d0a..58d372b 100644 --- a/run.js +++ b/run.js @@ -93,6 +93,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..84c63a0 100644 --- a/strings.json +++ b/strings.json @@ -1,74 +1,177 @@ { - "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}" + }, + "shorten_link": { + "english": "Shortened link from {user}: " + }, + "ignore_usage": { + "english": "{user}: Usage: ~ignore [module]. Modules you can ignore are: {modules}." + }, + "already_ignoring": { + "english": "{user}: You're already ignoring that module." + }, + "ignored": { + "english": "{user}: Now ignoring {module}." + }, + "invalid_ignore": { + "english": "{user}: That isn't a valid module name." + }, + "unignore_usage": { + "english": "{user}: Usage: ~unignore [module]. Modules you are currently ignoring: {modules}." + }, + "invalid_unignore": { + "english": "{user}: You're not ignoring that module or it doesn't exist." + }, + "unignored": { + "english": "{user}: No longer ignoring {module}." + }, + "command_typo": { + "english": "Did you mean '{command}'? Learn to type." + }, + "user_kicks": { + "english": "{user} has been kicked {kicks} times and has kicked people {kicked} times." + }, + "kicked_dbot": { + "english": "Thou shalt not kick {botname}" } }