From 7b515a4cc5ad051a7211a460eb6d269b7bb7ec2b Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:02:06 +0000 Subject: [PATCH 01/27] remove autoshorten because the shortener does not exist anymore --- modules/autoshorten.js | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 modules/autoshorten.js diff --git a/modules/autoshorten.js b/modules/autoshorten.js deleted file mode 100644 index 7199ec8..0000000 --- a/modules/autoshorten.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Module Name: AutoShorten - * Description: Automatically shorten link over a certain length and post the - * short link to the channel. - */ -var http = require('http'); - -var autoshorten = function(dbot) { - return { - 'name': 'autoshorten', - 'ignorable': true, - - 'listener': function(event) { - var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; - var urlMatches = event.message.match(urlRegex); - - 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. - var options = { - 'host': dbot.webHost, - 'port': dbot.webPort, - 'path': '/mkurl?url=' + escape(url) - }; - - http.get(options, function(res) { - res.setEncoding('utf8'); - res.on('data', function (response) { - event.reply(dbot.t('shorten_link', {'user': event.user}) + JSON.parse(response).surl); - }); - }); - } - }, - 'on': 'PRIVMSG' - }; -} - -exports.fetch = function(dbot) { - return autoshorten(dbot); -}; From b2ea634d8cc7d612570b147da993c75d2ba7c43d Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:04:52 +0000 Subject: [PATCH 02/27] Move all the modules to their own directories --- modules/admin/admin.js | 148 +++++++++++++++++++ modules/command/command.js | 104 +++++++++++++ modules/dice/dice.js | 105 +++++++++++++ modules/drama/drama.js | 96 ++++++++++++ modules/ignore/ignore.js | 81 ++++++++++ modules/js/js.js | 47 ++++++ modules/karma/karma.js | 8 + modules/kick/kick.js | 76 ++++++++++ modules/link/link.js | 52 +++++++ modules/poll/poll.js | 233 +++++++++++++++++++++++++++++ modules/puns/puns.js | 25 ++++ modules/quotes/quotes.js | 276 +++++++++++++++++++++++++++++++++++ modules/report/report.js | 52 +++++++ modules/spelling/spelling.js | 68 +++++++++ modules/web/web.js | 130 +++++++++++++++++ modules/youare/youare.js | 19 +++ 16 files changed, 1520 insertions(+) create mode 100644 modules/admin/admin.js create mode 100644 modules/command/command.js create mode 100644 modules/dice/dice.js create mode 100644 modules/drama/drama.js create mode 100644 modules/ignore/ignore.js create mode 100644 modules/js/js.js create mode 100644 modules/karma/karma.js create mode 100644 modules/kick/kick.js create mode 100644 modules/link/link.js create mode 100644 modules/poll/poll.js create mode 100644 modules/puns/puns.js create mode 100644 modules/quotes/quotes.js create mode 100644 modules/report/report.js create mode 100644 modules/spelling/spelling.js create mode 100644 modules/web/web.js create mode 100644 modules/youare/youare.js diff --git a/modules/admin/admin.js b/modules/admin/admin.js new file mode 100644 index 0000000..173e270 --- /dev/null +++ b/modules/admin/admin.js @@ -0,0 +1,148 @@ +/** + * Module Name: Admin + * Description: Set of commands which only one who is a DepressionBot + * administrator can run - as such, it has its own command execution listener. + */ +var fs = require('fs'); +var sys = require('sys') +var exec = require('child_process').exec; + +var admin = function(dbot) { + var commands = { + // Join a channel + 'join': function(event) { + var channel = event.params[1]; + if(event.allChannels.hasOwnProperty(channel)) { + event.reply("I'm already in that channel."); + } else { + dbot.instance.join(event, channel); + event.reply(dbot.t('join', {'channel': channel})); + } + }, + + // Leave a channel + 'part': function(event) { + var channel = event.params[1]; + if(!event.allChannels.hasOwnProperty(channel)) { + event.reply("I'm not in that channel."); + } else { + event.instance.part(event, channel); + event.reply(dbot.t('part', {'channel': channel})); + } + }, + + // Op admin caller in given channel + 'opme': function(event) { + var channel = event.params[1]; + + // If given channel isn't valid just op in current one. + if(!event.allChannels.hasOwnProperty(channel)) { + channel = event.channel.name; + } + dbot.instance.mode(event, channel, ' +o ' + event.user); + }, + + // Do a git pull and reload + 'greload': function(event) { + var child = exec("git pull", function (error, stdout, stderr) { + event.reply(dbot.t('gpull')); + commands.reload(event); + }.bind(this)); + }, + + // Reload DB, translations and modules. + 'reload': function(event) { + dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); + dbot.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); + dbot.reloadModules(); + event.reply(dbot.t('reload')); + }, + + // Say something in a channel (TODO probably doesn't work.) + 'say': function(event) { + var channel = event.params[1]; + if(event.params[1] === "@") { + var channel = event.channel.name; + } + var message = event.params.slice(2).join(' '); + dbot.say(event.server, channel, message); + }, + + // Load new module + 'load': function(event) { + var moduleName = event.params[1]; + dbot.moduleNames.push(moduleName); + dbot.reloadModules(); + event.reply(dbot.t('load_module', {'moduleName': moduleName})); + }, + + // Unload a loaded module + 'unload': function(event) { + var moduleName = event.params[1]; + if(dbot.moduleNames.include(moduleName)) { + var cacheKey = require.resolve('../modules/' + moduleName); + delete require.cache[cacheKey]; + + var moduleIndex = dbot.moduleNames.indexOf(moduleName); + dbot.moduleNames.splice(moduleIndex, 1); + dbot.reloadModules(); + + event.reply(dbot.t('unload_module', {'moduleName': moduleName})); + } else { + event.reply(dbot.t('unload_error', {'moduleName': moduleName})); + } + }, + + // Ban user from command or * + 'ban': function(event) { + var username = event.params[1]; + var command = event.params[2]; + + if(!dbot.db.bans.hasOwnProperty(command)) { + dbot.db.bans[command] = [ ]; + } + dbot.db.bans[command].push(username); + event.reply(dbot.t('banned', {'user': username, 'command': command})); + }, + + // Unban a user from command or * + 'unban': function(event) { + var username = event.params[1]; + var command = event.params[2]; + if(dbot.db.bans.hasOwnProperty(command) && dbot.db.bans[command].include(username)) { + dbot.db.bans[command].splice(dbot.db.bans[command].indexOf(username), 1); + event.reply(dbot.t('unbanned', {'user': username, 'command': command})); + } else { + event.reply(dbot.t('unban_error', {'user': username})); + } + }, + + // Lock quote category so quotes can't be removed + 'lock': function(event) { + var category = event.params[1]; + dbot.db.locks.push(category); + event.reply(dbot.t('qlock', {'category': category})); + } + }; + + return { + 'name': 'admin', + 'ignorable': false, + + /** + * Run the appropriate admin command given the input (and user). + */ + 'listener': function(event) { + var commandName = event.params[0]; + if(commands.hasOwnProperty(commandName) && dbot.admin.include(event.user)) { + commands[commandName](event); + dbot.save(); + } + }, + 'on': 'PRIVMSG' + }; +}; + +exports.fetch = function(dbot) { + return admin(dbot); +}; diff --git a/modules/command/command.js b/modules/command/command.js new file mode 100644 index 0000000..ea3043d --- /dev/null +++ b/modules/command/command.js @@ -0,0 +1,104 @@ +/** + * Module Name: Command + * Description: An essential module which maps PRIVMSG input to an appropriate + * command and then runs that command, given the user isn't banned from or + * ignoring that command. + */ +var command = function(dbot) { + /** + * Is user banned from using command? + */ + var isBanned = function(user, command) { + var banned = false; + if(dbot.db.bans.hasOwnProperty(command)) { + if(dbot.db.bans[command].include(user) || dbot.db.bans['*'].include(user)) { + banned = true; + } + } + return banned; + }; + + /** + * Is user ignoring command? + */ + var isIgnoring = function(user, command) { + var module = dbot.commandMap[command]; + var ignoring = false; + if(dbot.db.ignores.hasOwnProperty(user) && dbot.db.ignores[user].include(module)) { + ignoring = true; + } + return ignoring; + }; + + /** + * Apply Regex to event message, store result. Return false if it doesn't + * apply. + */ + var applyRegex = function(commandName, event) { + var applies = false; + if(dbot.commands[commandName].hasOwnProperty('regex')) { + var cRegex = dbot.commands[commandName].regex; + var q = event.message.valMatch(cRegex[0], cRegex[1]); + if(q) { + applies = true; + event.input = q; + } + } else { + applies = true; + } + return applies; + }; + + return { + 'name': 'command', + 'ignorable': false, + + 'commands': { + '~usage': function(event) { + var commandName = event.params[1]; + console.log(commandName); + if(dbot.commands.hasOwnProperty(commandName)) { + event.reply('Usage for ' + commandName + ': ' + + dbot.commands[commandName].usage); + } else { + event.reply('No usage information for ' + commandName); + } + } + }, + + /** + * Run the appropriate command given the input. + */ + 'listener': function(event) { + var commandName = event.params[0]; + if(!dbot.commands.hasOwnProperty(commandName)) { + commandName = '~'; + } + + if(isBanned(event.user, commandName)) { + event.reply(dbot.t('command_ban', {'user': event.user})); + } else { + if(!isIgnoring(event.user, commandName)) { + if(applyRegex(commandName, event)) { + dbot.commands[commandName](event); + dbot.save(); + } else { + if(commandName !== '~') { + if(dbot.commands[commandName].hasOwnProperty('usage')){ + event.reply('Usage: ' + dbot.commands[commandName].usage); + } else { + event.reply(dbot.t('syntax_error')); + } + } + } + } + } + }, + 'on': 'PRIVMSG' + }; +}; + +exports.fetch = function(dbot) { + return command(dbot); +}; + diff --git a/modules/dice/dice.js b/modules/dice/dice.js new file mode 100644 index 0000000..172822b --- /dev/null +++ b/modules/dice/dice.js @@ -0,0 +1,105 @@ +var parseDiceSpec = function (specString) { + var rawSpec = specString.valMatch(/^([0-9]*)d(%|[0-9]*)(|[+-][0-9]+)$/i, 4); + if (rawSpec !== false) { + if (rawSpec[2] === "%") { + rawSpec[2] = 100; + } + return { + "count": parseInt(rawSpec[1] || 1), + "sides": parseInt(rawSpec[2] || 6), + "modifier": parseInt(rawSpec[3] || 0) + }; + } else { + return false; + } +}; + +var normalizeDiceSpec = function (specString) { + var diceSpec = parseDiceSpec(specString); + + if (diceSpec["sides"] > 10000) { + return false; + } + + if (diceSpec["count"] > 1000) { + return false; + } + + if (diceSpec["count"] > 1) { + var count = diceSpec["count"]; + } else { + var count = ""; + } + + if (diceSpec["sides"] === 100) { + var sides = "%"; + } else { + var sides = diceSpec["sides"]; + } + + if (diceSpec["modifier"] > 0) { + var modifier = "+" + diceSpec["modifier"]; + } else if (diceSpec["modifier"] < 0) { + var modifier = diceSpec["modifier"]; + } else { + var modifier = ""; + } + + return (count + "d" + sides + modifier); +}; + +var dice = function(dbot) { + var commands = { + '~roll': function (event) { + var rolls = []; + + if (event.params.length === 1) { + event.params.push("d6"); + } + + for (var i = 1; i < event.params.length; i++) { + var diceSpec = parseDiceSpec(event.params[i]); + if (diceSpec === false) { + rolls.push([event.params[i], false]); + } else { + rolls.push([normalizeDiceSpec(event.params[i]), [], diceSpec["modifier"]]); + for (var j = 0; j < diceSpec["count"] ; j++) { + rolls[rolls.length-1][1].push(Math.ceil(Math.random() * diceSpec["sides"])); + } + } + } + + for (var i = 0; i < rolls.length; i++) { + if (rolls[i][1] === false) { + event.reply(rolls[i][0] + ": invalid dice spec"); + } else { + if (rolls[i][1].length > 1) { + var total = " (total " + rolls[i][1].sum(); + if (rolls[i][2] != 0) { + if (rolls[i][2] > 0) { + total += " + "; + } else { + total += " - "; + } + total += Math.abs(rolls[i][2]) + " -> " + (rolls[i][1].sum() + rolls[i][2]); + } + total += ")" + } else { + var total = ""; + } + event.reply(rolls[i][0] + ": " + rolls[i][1].join(" ") + total); + } + } + } + }; + + return { + 'name': 'dice', + 'commands': commands, + 'ignorable': true + }; +} + +exports.fetch = function(dbot) { + return dice(dbot); +}; diff --git a/modules/drama/drama.js b/modules/drama/drama.js new file mode 100644 index 0000000..fc9aa3a --- /dev/null +++ b/modules/drama/drama.js @@ -0,0 +1,96 @@ +/** + * Module Name: Drama + * Description: Experimental, you probably don't want it. + */ +var brain = require('brain'); + +var drama = function(dbot) { + var dbot = dbot; + var last = {}; + var options = { + 'backend': { + 'type': 'Redis', + 'options': { + 'hostname': 'localhost', + 'port': 6379, + 'name': 'dbotdrama' + } + }, + + 'thresholds': { + 'drama': 3, + 'beinganasshole': 3, + 'sd': 3, // self depracating + 'normal': 1 + }, + + 'def': 'normal' + }; + var bayes = new brain.BayesianClassifier(options); + + var commands = { + '~train': function(event) { + if(dbot.admin.include(event.user)) { + bayes.train(last[event.params[1]][event.params[2]], event.params[3]); + event.reply('Last thing ' + event.params[2] + ' said in ' + + event.params[1] + ' (' + last[event.params[1]][event.params[2]] + ') classified as \'' + event.params[3] + '\''); + } + }, + + '~rtrain': function(event) { + if(dbot.admin.include(event.user)) { + var category = event.params[1]; + event.params.splice(0, 2); + var msg = event.params.join(' '); + bayes.train(msg, category); + event.reply('\'' + msg + '\' classified as \'' + category + '\''); + } + }, + + '~classify': function(event) { + event.params.splice(0, 1); + var msg = event.params.join(' '); + bayes.classify(msg, function(category) { + event.reply('Classified as: ' + category + '!'); + }.bind(this)); + } + } + + return { + 'name': 'drama', + 'ignorable': false, + 'commands': commands, + + 'listener': function(data) { + var category = bayes.classify(data.message, function(category) { + if(category !== 'normal') { + if(category === 'beinganasshole') { + if(dbot.db.drama.beinganasshole.hasOwnProperty(event.user)) { + dbot.db.drama.beinganasshole[event.user]++; + } else { + dbot.db.drama.beinganasshole[event.user] = 1; + } + } else if(category === 'sd') { + if(dbot.db.drama.sd.hasOwnProperty(event.user)) { + dbot.db.drama.sd[event.user]++; + } else { + dbot.db.drama.sd[event.user] = 1; + } + } + } + }.bind(this)); + + if(last.hasOwnProperty(event.channel)) { + last[event.channel][event.user] = data.message; + } else { + last[event.channel] = { }; + last[event.channel][event.user] = data.message; + } + }, + 'on': 'PRIVMSG' + }; +} + +exports.fetch = function(dbot) { + return drama(dbot); +}; diff --git a/modules/ignore/ignore.js b/modules/ignore/ignore.js new file mode 100644 index 0000000..b7330b7 --- /dev/null +++ b/modules/ignore/ignore.js @@ -0,0 +1,81 @@ +/** + * Module Name: Ignore + * Description: Handles commands in which users can choose to ignore listeners + * and commands from certain modules. It also populates the JSBot instance with + * this information, since that actually performs the ignorance. + */ +var ignore = function(dbot) { + var commands = { + '~ignore': function(event) { + var ignorableModules = []; + for(var i=0;i(.*)<\/title>/, 2); + if(title) { + event.reply(title[1]); + } else { + event.reply('no title found'); + } + } + }); + } + }; + + return { + 'name': 'link', + 'ignorable': true, + 'commands': commands, + + 'listener': function(event) { + var urlMatches = event.message.match(urlRegex); + if(urlMatches !== null) { + links[event.channel.name] = urlMatches[0]; + } + }, + 'on': 'PRIVMSG' + }; +}; + +exports.fetch = function(dbot) { + return link(dbot); +}; diff --git a/modules/poll/poll.js b/modules/poll/poll.js new file mode 100644 index 0000000..2b82282 --- /dev/null +++ b/modules/poll/poll.js @@ -0,0 +1,233 @@ +var poll = function(dbot) { + var polls = dbot.db.polls; + var commands = { + '~newpoll': function(event) { + var av = event.input[1] != undefined; + var name = event.input[2]; + var options = event.input[3].split(','); + var description = event.input[4]; + + if(name === undefined || name === 'help') { + event.reply(dbot.t('newpoll_usage')); + } else { + if(polls.hasOwnProperty(name)) { + event.reply(dbot.t('poll_exists', {'name': name})); + } else { + if(av) { + polls[name] = { + 'av': av, + 'name': name, + 'description': description, + 'owner': event.user, + 'votes': {}, + 'options': [] + }; + for(var i=0;i 0) { + altKey = key.replace(/ /g, '_'); + } + + if(key.charAt(0) !== '_') { // lol + if(quotes.hasOwnProperty(key)) { + event.reply(key + ': ' + interpolatedQuote(key)); + } else if(quotes.hasOwnProperty(altKey)) { + event.reply(altKey + ': ' + interpolatedQuote(altKey)); + } else { + event.reply(dbot.t('category_not_found', {'category': key})); + } + } + }, + + // Shows a list of the biggest categories + '~qstats': function(event) { + var qSizes = Object.prototype.sort(quotes, function(key, obj) { return obj[key].length }); + qSizes = qSizes.slice(qSizes.length - 10).reverse(); + + var qString = dbot.t('large_categories'); + for(var i=0;i 0) { + event.reply(dbot.t('prune', {'categories': pruned.join(", ")})); + } else { + event.reply(dbot.t('no_prune')); + } + } + }; + + commands['~'].regex = [/^~([\d\w\s-]*)/, 2]; + commands['~q'].regex = [/^~q ([\d\w\s-]*)/, 2]; + commands['~qsearch'].regex = [/^~qsearch ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; + commands['~rm'].regex = [/^~rm ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; + commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2]; + commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; + + commands['~q'].usage = '~q [category]'; + commands['~qsearch'].usage = '~qsearch [category]=[search]'; + commands['~rm'].usage = '~rm [category]=[quote to delete]'; + commands['~rmlast'].usage = '~rmlast [category]' + commands['~qadd'].usage = '~qadd [category]=[content]'; + + return { + 'name': 'quotes', + 'ignorable': true, + 'commands': commands, + + 'onLoad': function() { + dbot.timers.addTimer(1000 * 60 * 3, function() { + rmAllowed = true; + }); + }, + + 'listener': function(event) { + if((dbot.db.ignores.hasOwnProperty(event) && + dbot.db.ignores[event.user].include(name)) == false) { + if(event.user == 'reality') { + var once = event.message.valMatch(/^I ([\d\w\s,'-]* once)/, 2); + } else { + var once = event.message.valMatch(/^reality ([\d\w\s,'-]* once)/, 2); + } + + if(once) { + if((dbot.db.bans.hasOwnProperty('~qadd') && + dbot.db.bans['~qadd'].include(event.user)) || + dbot.db.bans['*'].include(event.user)) { + event.reply(dbot.t('command_ban', {'user': event.user})); + } else { + if(!dbot.db.quoteArrs.hasOwnProperty('realityonce')) { + dbot.db.quoteArrs['realityonce'] = []; + } + if(dbot.db.quoteArrs['realityonce'].include('reality ' + once[1] + '.')) { + event.reply(event.user + ': reality has already done that once.'); + } else { + dbot.db.quoteArrs['realityonce'].push('reality ' + once[1] + '.'); + addStack.push('realityonce'); + rmAllowed = true; + event.reply('\'reality ' + once[1] + '.\' saved.'); + } + } + } + } + }, + + 'on': 'PRIVMSG' + }; +}; + +exports.fetch = function(dbot) { + return quotes(dbot); +}; diff --git a/modules/report/report.js b/modules/report/report.js new file mode 100644 index 0000000..f3f4c2f --- /dev/null +++ b/modules/report/report.js @@ -0,0 +1,52 @@ +var report = function(dbot) { + var commands = { + '~report': function(event) { + var channelName = event.input[1]; + var nick = event.input[2]; + var reason = event.input[3]; + + if(event.allChannels.hasOwnProperty(channelName)) { + var channel = event.allChannels[channelName]; + if(channel.nicks.hasOwnProperty(nick)) { + var ops = []; + for(var possibOps in channel.nicks) { + if(channel.nicks[possibOps].op == true) { + ops.push(possibOps); + } + } + + // Does the channel have an admin channel? + if(event.allChannels.hasOwnProperty('#' + channelName)) { + ops.push('#' + channelName); + } + + for(var i=0;i 0)) { + winner = candidates[i]; + winnerDistance = distance; + } + } + + if(winnerDistance < Math.ceil(winner.length * 1.33)) { + if(winner !== correction) { + var fix = last[event.channel.name][candidate].replace(winner, correction); + if (/^.ACTION/.test(fix)) { + fix = fix.replace(/^.ACTION/, '/me'); + } + last[event.channel.name][candidate] = fix; + var output = { + 'fix': fix, + 'correcter': event.user, + 'candidate': candidate + }; + output_callback(output); + } + } + } + + return { + 'name': 'spelling', + 'ignorable': true, + + 'listener': function(event) { + var q = event.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3); + var otherQ = event.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4); + if(q) { + correct(event, q[1] || q[2], event.user, function (e) { + event.reply(dbot.t('spelling_self', e)); + }); + } else if(otherQ) { + correct(event, otherQ[2] || otherQ[3], otherQ[1], function (e) { + event.reply(dbot.t('spelling_other', e)); + }); + } else { + if(last.hasOwnProperty(event.channel.name)) { + last[event.channel.name][event.user] = event.message; + } else { + last[event.channel.name] = { }; + last[event.channel.name][event.user] = event.message; + } + } + }, + 'on': 'PRIVMSG' + } +} + +exports.fetch = function(dbot) { + return spelling(dbot); +}; diff --git a/modules/web/web.js b/modules/web/web.js new file mode 100644 index 0000000..1be542a --- /dev/null +++ b/modules/web/web.js @@ -0,0 +1,130 @@ +var express = require('express'); + +var webInterface = function(dbot) { + var pub = 'public'; + var app = express.createServer(); + + app.use(express.compiler({ src: pub, enable: ['sass'] })); + app.use(express.static(pub)); + app.set('view engine', 'jade'); + + app.get('/', function(req, res) { + res.render('index', { 'name': dbot.name }); + }); + + app.get('/connections', function(req, res) { + var connections = Object.keys(dbot.instance.connections); + res.render('connections', { 'name': dbot.name, 'connections': connections }); + }); + + app.get('/channels/:connection', function(req, res) { + var connection = req.params.connection; + if(dbot.instance.connections.hasOwnProperty(connection)) { + var channels = Object.keys(dbot.instance.connections[connection].channels); + res.render('channels', { 'name': dbot.name, 'connection': connection, 'channels': channels}); + } else { + res.render('error', { 'name': dbot.name, 'message': 'No such connection.' }); + } + }); + + app.get('/users/:connection/:channel', function(req, res) { + var connection = req.params.connection; + var channel = '#' + req.params.channel; + var connections = dbot.instance.connections; + + if(connections.hasOwnProperty(connection) && + connections[connection].channels.hasOwnProperty(channel)) { + var nicks = Object.keys(connections[connection].channels[channel].nicks); + res.render('users', { 'name': dbot.name, 'connection': connection, + 'channel': channel, 'nicks': nicks }); + } else { + res.render('error', { 'name': dbot.name, 'message': 'No such connection or channel.' }); + } + }); + + app.get('/user/:connection/:channel/:user', function(req, res) { + var connection = req.params.connection; + var channel = '#' + req.params.channel; + var user = dbot.cleanNick(req.params.user); + + var quoteCount = 'no'; + if(dbot.db.quoteArrs.hasOwnProperty(user)) { + var quoteCount = dbot.db.quoteArrs[user].length; + } + + if(!dbot.db.kicks.hasOwnProperty(req.params.user)) { + var kicks = '0'; + } else { + var kicks = dbot.db.kicks[req.params.user]; + } + + if(!dbot.db.kickers.hasOwnProperty(req.params.user)) { + var kicked = '0'; + } else { + var kicked = dbot.db.kickers[req.params.user]; + } + + res.render('user', { 'name': dbot.name, 'user': req.params.user, + 'channel': channel, 'connection': connection, 'cleanUser': user, + 'quotecount': quoteCount, 'kicks': kicks, 'kicked': kicked }); + }); + + // Lists the quote categories + app.get('/quotes', function(req, res) { + res.render('quotelist', { 'name': dbot.name, 'quotelist': Object.keys(dbot.db.quoteArrs) }); + }); + + // Lists quotes in a category + app.get('/quotes/:key', function(req, res) { + var key = req.params.key.toLowerCase(); + if(dbot.db.quoteArrs.hasOwnProperty(key)) { + res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[key], locals: { 'url_regex': RegExp.prototype.url_regex() } }); + } else { + res.render('error', { 'name': dbot.name, 'message': 'No quotes under that key.' }); + } + }); + + // Load random quote category page + app.get('/rq', function(req, res) { + var rCategory = Object.keys(dbot.db.quoteArrs).random(); + res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[rCategory], locals: { 'url_regex': RegExp.prototype.url_regex() } }); + }); + + // Lists all of the polls + app.get('/polls', function(req, res) { + res.render('polllist', { 'name': dbot.name, 'polllist': Object.keys(dbot.db.polls) }); + }); + + // Shows the results of a poll + app.get('/polls/:key', function(req, res) { + var key = req.params.key.toLowerCase(); + if(dbot.db.polls.hasOwnProperty(key) && dbot.db.polls[key].hasOwnProperty('description')) { + // tally the votes + var totalVotes = 0; + for( var v in dbot.db.polls[key].votes ) { + var N = Number(dbot.db.polls[key].votes[v]); + if( !isNaN(N) ) { + totalVotes += N; + } + } + res.render('polls', { 'name': dbot.name, 'description': dbot.db.polls[key].description, 'votees': Object.keys(dbot.db.polls[key].votees), 'options': dbot.db.polls[key].votes, locals: { 'totalVotes': totalVotes, 'url_regex': RegExp.prototype.url_regex() } }); + } else { + res.render('error', { 'name': dbot.name, 'message': 'No polls under that key.' }); + } + }); + + app.listen(dbot.webPort); + + return { + 'name': 'web', + 'ignorable': false, + + 'onDestroy': function() { + app.close(); + } + }; +}; + +exports.fetch = function(dbot) { + return webInterface(dbot); +}; diff --git a/modules/youare/youare.js b/modules/youare/youare.js new file mode 100644 index 0000000..ddb25e0 --- /dev/null +++ b/modules/youare/youare.js @@ -0,0 +1,19 @@ +var youAre = function(dbot) { + return { + 'name': 'youare', + 'ignorable': false, + + 'listener': function(event) { + var key = event.message.valMatch(/(\bis\b|\bare\b)\s+([\w\s\d]*?)(\s+)?(,|\.|\band\b|$)/, 5); + + if(key && key[2] != "" && Number.prototype.chanceIn(1, 100) && event.user != 'aisbot') { + event.reply(event.user + ': You\'re ' + key[2] + '.'); + } + }, + 'on': 'PRIVMSG' + }; +}; + +exports.fetch = function(dbot) { + return youAre(dbot); +}; From b622d7a239795b6e6f3cc802b4076a1b3e359265 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:18:27 +0000 Subject: [PATCH 03/27] give all modules their own folders. overhauled admin strings --- modules/admin.js | 148 -------------------- modules/admin/strings.json | 68 +++++++++ modules/command.js | 104 -------------- modules/dice.js | 105 -------------- modules/drama.js | 96 ------------- modules/ignore.js | 81 ----------- modules/js.js | 47 ------- modules/kick.js | 76 ---------- modules/link.js | 52 ------- modules/poll.js | 233 ------------------------------- modules/puns.js | 25 ---- modules/quotes.js | 276 ------------------------------------- modules/quotes/quotes.js | 1 + modules/report.js | 52 ------- modules/spelling.js | 68 --------- modules/web.js | 130 ----------------- modules/youare.js | 19 --- strings.json | 79 ----------- 18 files changed, 69 insertions(+), 1591 deletions(-) delete mode 100644 modules/admin.js create mode 100644 modules/admin/strings.json delete mode 100644 modules/command.js delete mode 100644 modules/dice.js delete mode 100644 modules/drama.js delete mode 100644 modules/ignore.js delete mode 100644 modules/js.js delete mode 100644 modules/kick.js delete mode 100644 modules/link.js delete mode 100644 modules/poll.js delete mode 100644 modules/puns.js delete mode 100644 modules/quotes.js delete mode 100644 modules/report.js delete mode 100644 modules/spelling.js delete mode 100644 modules/web.js delete mode 100644 modules/youare.js diff --git a/modules/admin.js b/modules/admin.js deleted file mode 100644 index 173e270..0000000 --- a/modules/admin.js +++ /dev/null @@ -1,148 +0,0 @@ -/** - * Module Name: Admin - * Description: Set of commands which only one who is a DepressionBot - * administrator can run - as such, it has its own command execution listener. - */ -var fs = require('fs'); -var sys = require('sys') -var exec = require('child_process').exec; - -var admin = function(dbot) { - var commands = { - // Join a channel - 'join': function(event) { - var channel = event.params[1]; - if(event.allChannels.hasOwnProperty(channel)) { - event.reply("I'm already in that channel."); - } else { - dbot.instance.join(event, channel); - event.reply(dbot.t('join', {'channel': channel})); - } - }, - - // Leave a channel - 'part': function(event) { - var channel = event.params[1]; - if(!event.allChannels.hasOwnProperty(channel)) { - event.reply("I'm not in that channel."); - } else { - event.instance.part(event, channel); - event.reply(dbot.t('part', {'channel': channel})); - } - }, - - // Op admin caller in given channel - 'opme': function(event) { - var channel = event.params[1]; - - // If given channel isn't valid just op in current one. - if(!event.allChannels.hasOwnProperty(channel)) { - channel = event.channel.name; - } - dbot.instance.mode(event, channel, ' +o ' + event.user); - }, - - // Do a git pull and reload - 'greload': function(event) { - var child = exec("git pull", function (error, stdout, stderr) { - event.reply(dbot.t('gpull')); - commands.reload(event); - }.bind(this)); - }, - - // Reload DB, translations and modules. - 'reload': function(event) { - dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); - dbot.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); - dbot.reloadModules(); - event.reply(dbot.t('reload')); - }, - - // Say something in a channel (TODO probably doesn't work.) - 'say': function(event) { - var channel = event.params[1]; - if(event.params[1] === "@") { - var channel = event.channel.name; - } - var message = event.params.slice(2).join(' '); - dbot.say(event.server, channel, message); - }, - - // Load new module - 'load': function(event) { - var moduleName = event.params[1]; - dbot.moduleNames.push(moduleName); - dbot.reloadModules(); - event.reply(dbot.t('load_module', {'moduleName': moduleName})); - }, - - // Unload a loaded module - 'unload': function(event) { - var moduleName = event.params[1]; - if(dbot.moduleNames.include(moduleName)) { - var cacheKey = require.resolve('../modules/' + moduleName); - delete require.cache[cacheKey]; - - var moduleIndex = dbot.moduleNames.indexOf(moduleName); - dbot.moduleNames.splice(moduleIndex, 1); - dbot.reloadModules(); - - event.reply(dbot.t('unload_module', {'moduleName': moduleName})); - } else { - event.reply(dbot.t('unload_error', {'moduleName': moduleName})); - } - }, - - // Ban user from command or * - 'ban': function(event) { - var username = event.params[1]; - var command = event.params[2]; - - if(!dbot.db.bans.hasOwnProperty(command)) { - dbot.db.bans[command] = [ ]; - } - dbot.db.bans[command].push(username); - event.reply(dbot.t('banned', {'user': username, 'command': command})); - }, - - // Unban a user from command or * - 'unban': function(event) { - var username = event.params[1]; - var command = event.params[2]; - if(dbot.db.bans.hasOwnProperty(command) && dbot.db.bans[command].include(username)) { - dbot.db.bans[command].splice(dbot.db.bans[command].indexOf(username), 1); - event.reply(dbot.t('unbanned', {'user': username, 'command': command})); - } else { - event.reply(dbot.t('unban_error', {'user': username})); - } - }, - - // Lock quote category so quotes can't be removed - 'lock': function(event) { - var category = event.params[1]; - dbot.db.locks.push(category); - event.reply(dbot.t('qlock', {'category': category})); - } - }; - - return { - 'name': 'admin', - 'ignorable': false, - - /** - * Run the appropriate admin command given the input (and user). - */ - 'listener': function(event) { - var commandName = event.params[0]; - if(commands.hasOwnProperty(commandName) && dbot.admin.include(event.user)) { - commands[commandName](event); - dbot.save(); - } - }, - 'on': 'PRIVMSG' - }; -}; - -exports.fetch = function(dbot) { - return admin(dbot); -}; diff --git a/modules/admin/strings.json b/modules/admin/strings.json new file mode 100644 index 0000000..8ecacd0 --- /dev/null +++ b/modules/admin/strings.json @@ -0,0 +1,68 @@ +{ + "join": { + "english": "Joined {channel}", + "spanish" : "Entrado en {channel}", + "na'vi": "fpxäkìm {channel}(nemfa)", + "welsh": "Wedi ymuno {channel}" + }, + "part": { + "english": "Left {channel}", + "spanish" : "Abandonada {channel}", + "na'vi": "Hum {channel}", + "welsh": "Wedi gadael {channel}" + }, + "gpull": { + "english": "Git pulled that shit.", + "spanish": "Hecho git pull en esta mierda.", + "na'vi": "Gìtìl fì'uti stamarsìm.", + "welsh": "Wedi tynnu git yr cach na i gyd" + }, + "reload": { + "english": "Reloaded that shit.", + "spanish": "Recargado esta mierda.", + "na'vi": "Oel fìuti stìyeftxaw.", + "welsh": "Ail-lwytho'r cach na" + }, + "load_module": { + "english": "Loaded new module: {moduleName}", + "spanish": "Cargado módulo nuevo: {moduleName}", + "na'vi": "Oel {moduleName}it amip stìyeftxaw.", + "welsh": "Wedi llwytho modiwl newydd: {moduleName}" + }, + "unload_module": { + "english": "Turned off module: {moduleName}", + "spanish": "Descargado módulo: {moduleName}", + "na'vi": "Oel {moduleName} tswìya'.", + "welsh": "Wedi troi ffwrdd y modiwl: {moduleName}" + }, + "unload_error": { + "english": "{moduleName} isn't loaded. Idiot.", + "spanish": "{moduleName} no está cargado. Idiota.", + "na'vi": "Oel {moduleName}it omum. Nga skxawng lu.", + "welsh": "Di {moduleName} ddim wedi llwytho. Twpsyn" + }, + "banned": { + "english": "{user} banned from {command}", + "spanish": "{user} está prohibido de usar {command}", + "na'vi": "{command}ìri {user} ke tung.", + "welsh": "{user} wedi ei gohurio o {command}" + }, + "unbanned": { + "english": "{user} unbanned from {command}", + "spanish": "{user} no está prohibido de user {command}", + "na'vi": "{command}ìri {user} tung set.", + "welsh": "{user} wedi ei dad-wahardd o {command}" + }, + "unban_error": { + "english": "{user} wasn't banned from that command, fool.", + "spanish": "{user} no fue prohibido de esta instrucción, tont@.", + "na'vi": "{user} fìtsu'oti tamung srekrr, nga skxawng lu.", + "welsh": "Nid oedd {user} wedi ei wahardd o'r gyrchymun yna, fŵl" + }, + "qlock": { + "english": "Locked quote category: {category}", + "spanish": "Cerrado la categoría: {category}", + "na'vi": "{category}ìri oel 'upxareti fmoli", + "welsh": "Categori wedi cloi: {category}" + } +} diff --git a/modules/command.js b/modules/command.js deleted file mode 100644 index ea3043d..0000000 --- a/modules/command.js +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Module Name: Command - * Description: An essential module which maps PRIVMSG input to an appropriate - * command and then runs that command, given the user isn't banned from or - * ignoring that command. - */ -var command = function(dbot) { - /** - * Is user banned from using command? - */ - var isBanned = function(user, command) { - var banned = false; - if(dbot.db.bans.hasOwnProperty(command)) { - if(dbot.db.bans[command].include(user) || dbot.db.bans['*'].include(user)) { - banned = true; - } - } - return banned; - }; - - /** - * Is user ignoring command? - */ - var isIgnoring = function(user, command) { - var module = dbot.commandMap[command]; - var ignoring = false; - if(dbot.db.ignores.hasOwnProperty(user) && dbot.db.ignores[user].include(module)) { - ignoring = true; - } - return ignoring; - }; - - /** - * Apply Regex to event message, store result. Return false if it doesn't - * apply. - */ - var applyRegex = function(commandName, event) { - var applies = false; - if(dbot.commands[commandName].hasOwnProperty('regex')) { - var cRegex = dbot.commands[commandName].regex; - var q = event.message.valMatch(cRegex[0], cRegex[1]); - if(q) { - applies = true; - event.input = q; - } - } else { - applies = true; - } - return applies; - }; - - return { - 'name': 'command', - 'ignorable': false, - - 'commands': { - '~usage': function(event) { - var commandName = event.params[1]; - console.log(commandName); - if(dbot.commands.hasOwnProperty(commandName)) { - event.reply('Usage for ' + commandName + ': ' + - dbot.commands[commandName].usage); - } else { - event.reply('No usage information for ' + commandName); - } - } - }, - - /** - * Run the appropriate command given the input. - */ - 'listener': function(event) { - var commandName = event.params[0]; - if(!dbot.commands.hasOwnProperty(commandName)) { - commandName = '~'; - } - - if(isBanned(event.user, commandName)) { - event.reply(dbot.t('command_ban', {'user': event.user})); - } else { - if(!isIgnoring(event.user, commandName)) { - if(applyRegex(commandName, event)) { - dbot.commands[commandName](event); - dbot.save(); - } else { - if(commandName !== '~') { - if(dbot.commands[commandName].hasOwnProperty('usage')){ - event.reply('Usage: ' + dbot.commands[commandName].usage); - } else { - event.reply(dbot.t('syntax_error')); - } - } - } - } - } - }, - 'on': 'PRIVMSG' - }; -}; - -exports.fetch = function(dbot) { - return command(dbot); -}; - diff --git a/modules/dice.js b/modules/dice.js deleted file mode 100644 index 172822b..0000000 --- a/modules/dice.js +++ /dev/null @@ -1,105 +0,0 @@ -var parseDiceSpec = function (specString) { - var rawSpec = specString.valMatch(/^([0-9]*)d(%|[0-9]*)(|[+-][0-9]+)$/i, 4); - if (rawSpec !== false) { - if (rawSpec[2] === "%") { - rawSpec[2] = 100; - } - return { - "count": parseInt(rawSpec[1] || 1), - "sides": parseInt(rawSpec[2] || 6), - "modifier": parseInt(rawSpec[3] || 0) - }; - } else { - return false; - } -}; - -var normalizeDiceSpec = function (specString) { - var diceSpec = parseDiceSpec(specString); - - if (diceSpec["sides"] > 10000) { - return false; - } - - if (diceSpec["count"] > 1000) { - return false; - } - - if (diceSpec["count"] > 1) { - var count = diceSpec["count"]; - } else { - var count = ""; - } - - if (diceSpec["sides"] === 100) { - var sides = "%"; - } else { - var sides = diceSpec["sides"]; - } - - if (diceSpec["modifier"] > 0) { - var modifier = "+" + diceSpec["modifier"]; - } else if (diceSpec["modifier"] < 0) { - var modifier = diceSpec["modifier"]; - } else { - var modifier = ""; - } - - return (count + "d" + sides + modifier); -}; - -var dice = function(dbot) { - var commands = { - '~roll': function (event) { - var rolls = []; - - if (event.params.length === 1) { - event.params.push("d6"); - } - - for (var i = 1; i < event.params.length; i++) { - var diceSpec = parseDiceSpec(event.params[i]); - if (diceSpec === false) { - rolls.push([event.params[i], false]); - } else { - rolls.push([normalizeDiceSpec(event.params[i]), [], diceSpec["modifier"]]); - for (var j = 0; j < diceSpec["count"] ; j++) { - rolls[rolls.length-1][1].push(Math.ceil(Math.random() * diceSpec["sides"])); - } - } - } - - for (var i = 0; i < rolls.length; i++) { - if (rolls[i][1] === false) { - event.reply(rolls[i][0] + ": invalid dice spec"); - } else { - if (rolls[i][1].length > 1) { - var total = " (total " + rolls[i][1].sum(); - if (rolls[i][2] != 0) { - if (rolls[i][2] > 0) { - total += " + "; - } else { - total += " - "; - } - total += Math.abs(rolls[i][2]) + " -> " + (rolls[i][1].sum() + rolls[i][2]); - } - total += ")" - } else { - var total = ""; - } - event.reply(rolls[i][0] + ": " + rolls[i][1].join(" ") + total); - } - } - } - }; - - return { - 'name': 'dice', - 'commands': commands, - 'ignorable': true - }; -} - -exports.fetch = function(dbot) { - return dice(dbot); -}; diff --git a/modules/drama.js b/modules/drama.js deleted file mode 100644 index fc9aa3a..0000000 --- a/modules/drama.js +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Module Name: Drama - * Description: Experimental, you probably don't want it. - */ -var brain = require('brain'); - -var drama = function(dbot) { - var dbot = dbot; - var last = {}; - var options = { - 'backend': { - 'type': 'Redis', - 'options': { - 'hostname': 'localhost', - 'port': 6379, - 'name': 'dbotdrama' - } - }, - - 'thresholds': { - 'drama': 3, - 'beinganasshole': 3, - 'sd': 3, // self depracating - 'normal': 1 - }, - - 'def': 'normal' - }; - var bayes = new brain.BayesianClassifier(options); - - var commands = { - '~train': function(event) { - if(dbot.admin.include(event.user)) { - bayes.train(last[event.params[1]][event.params[2]], event.params[3]); - event.reply('Last thing ' + event.params[2] + ' said in ' + - event.params[1] + ' (' + last[event.params[1]][event.params[2]] + ') classified as \'' + event.params[3] + '\''); - } - }, - - '~rtrain': function(event) { - if(dbot.admin.include(event.user)) { - var category = event.params[1]; - event.params.splice(0, 2); - var msg = event.params.join(' '); - bayes.train(msg, category); - event.reply('\'' + msg + '\' classified as \'' + category + '\''); - } - }, - - '~classify': function(event) { - event.params.splice(0, 1); - var msg = event.params.join(' '); - bayes.classify(msg, function(category) { - event.reply('Classified as: ' + category + '!'); - }.bind(this)); - } - } - - return { - 'name': 'drama', - 'ignorable': false, - 'commands': commands, - - 'listener': function(data) { - var category = bayes.classify(data.message, function(category) { - if(category !== 'normal') { - if(category === 'beinganasshole') { - if(dbot.db.drama.beinganasshole.hasOwnProperty(event.user)) { - dbot.db.drama.beinganasshole[event.user]++; - } else { - dbot.db.drama.beinganasshole[event.user] = 1; - } - } else if(category === 'sd') { - if(dbot.db.drama.sd.hasOwnProperty(event.user)) { - dbot.db.drama.sd[event.user]++; - } else { - dbot.db.drama.sd[event.user] = 1; - } - } - } - }.bind(this)); - - if(last.hasOwnProperty(event.channel)) { - last[event.channel][event.user] = data.message; - } else { - last[event.channel] = { }; - last[event.channel][event.user] = data.message; - } - }, - 'on': 'PRIVMSG' - }; -} - -exports.fetch = function(dbot) { - return drama(dbot); -}; diff --git a/modules/ignore.js b/modules/ignore.js deleted file mode 100644 index b7330b7..0000000 --- a/modules/ignore.js +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Module Name: Ignore - * Description: Handles commands in which users can choose to ignore listeners - * and commands from certain modules. It also populates the JSBot instance with - * this information, since that actually performs the ignorance. - */ -var ignore = function(dbot) { - var commands = { - '~ignore': function(event) { - var ignorableModules = []; - for(var i=0;i(.*)<\/title>/, 2); - if(title) { - event.reply(title[1]); - } else { - event.reply('no title found'); - } - } - }); - } - }; - - return { - 'name': 'link', - 'ignorable': true, - 'commands': commands, - - 'listener': function(event) { - var urlMatches = event.message.match(urlRegex); - if(urlMatches !== null) { - links[event.channel.name] = urlMatches[0]; - } - }, - 'on': 'PRIVMSG' - }; -}; - -exports.fetch = function(dbot) { - return link(dbot); -}; diff --git a/modules/poll.js b/modules/poll.js deleted file mode 100644 index 2b82282..0000000 --- a/modules/poll.js +++ /dev/null @@ -1,233 +0,0 @@ -var poll = function(dbot) { - var polls = dbot.db.polls; - var commands = { - '~newpoll': function(event) { - var av = event.input[1] != undefined; - var name = event.input[2]; - var options = event.input[3].split(','); - var description = event.input[4]; - - if(name === undefined || name === 'help') { - event.reply(dbot.t('newpoll_usage')); - } else { - if(polls.hasOwnProperty(name)) { - event.reply(dbot.t('poll_exists', {'name': name})); - } else { - if(av) { - polls[name] = { - 'av': av, - 'name': name, - 'description': description, - 'owner': event.user, - 'votes': {}, - 'options': [] - }; - for(var i=0;i 0) { - altKey = key.replace(/ /g, '_'); - } - - if(key.charAt(0) !== '_') { // lol - if(quotes.hasOwnProperty(key)) { - event.reply(key + ': ' + interpolatedQuote(key)); - } else if(quotes.hasOwnProperty(altKey)) { - event.reply(altKey + ': ' + interpolatedQuote(altKey)); - } else { - event.reply(dbot.t('category_not_found', {'category': key})); - } - } - }, - - // Shows a list of the biggest categories - '~qstats': function(event) { - var qSizes = Object.prototype.sort(quotes, function(key, obj) { return obj[key].length }); - qSizes = qSizes.slice(qSizes.length - 10).reverse(); - - var qString = dbot.t('large_categories'); - for(var i=0;i 0) { - event.reply(dbot.t('prune', {'categories': pruned.join(", ")})); - } else { - event.reply(dbot.t('no_prune')); - } - } - }; - - commands['~'].regex = [/^~([\d\w\s-]*)/, 2]; - commands['~q'].regex = [/^~q ([\d\w\s-]*)/, 2]; - commands['~qsearch'].regex = [/^~qsearch ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; - commands['~rm'].regex = [/^~rm ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; - commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2]; - commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; - - commands['~q'].usage = '~q [category]'; - commands['~qsearch'].usage = '~qsearch [category]=[search]'; - commands['~rm'].usage = '~rm [category]=[quote to delete]'; - commands['~rmlast'].usage = '~rmlast [category]' - commands['~qadd'].usage = '~qadd [category]=[content]'; - - return { - 'name': 'quotes', - 'ignorable': true, - 'commands': commands, - - 'onLoad': function() { - dbot.timers.addTimer(1000 * 60 * 3, function() { - rmAllowed = true; - }); - }, - - 'listener': function(event) { - if((dbot.db.ignores.hasOwnProperty(event) && - dbot.db.ignores[event.user].include(name)) == false) { - if(event.user == 'reality') { - var once = event.message.valMatch(/^I ([\d\w\s,'-]* once)/, 2); - } else { - var once = event.message.valMatch(/^reality ([\d\w\s,'-]* once)/, 2); - } - - if(once) { - if((dbot.db.bans.hasOwnProperty('~qadd') && - dbot.db.bans['~qadd'].include(event.user)) || - dbot.db.bans['*'].include(event.user)) { - event.reply(dbot.t('command_ban', {'user': event.user})); - } else { - if(!dbot.db.quoteArrs.hasOwnProperty('realityonce')) { - dbot.db.quoteArrs['realityonce'] = []; - } - if(dbot.db.quoteArrs['realityonce'].include('reality ' + once[1] + '.')) { - event.reply(event.user + ': reality has already done that once.'); - } else { - dbot.db.quoteArrs['realityonce'].push('reality ' + once[1] + '.'); - addStack.push('realityonce'); - rmAllowed = true; - event.reply('\'reality ' + once[1] + '.\' saved.'); - } - } - } - } - }, - - 'on': 'PRIVMSG' - }; -}; - -exports.fetch = function(dbot) { - return quotes(dbot); -}; diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index bb00730..35a8765 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -237,6 +237,7 @@ var quotes = function(dbot) { }, 'listener': function(event) { + // Reality Once listener if((dbot.db.ignores.hasOwnProperty(event) && dbot.db.ignores[event.user].include(name)) == false) { if(event.user == 'reality') { diff --git a/modules/report.js b/modules/report.js deleted file mode 100644 index f3f4c2f..0000000 --- a/modules/report.js +++ /dev/null @@ -1,52 +0,0 @@ -var report = function(dbot) { - var commands = { - '~report': function(event) { - var channelName = event.input[1]; - var nick = event.input[2]; - var reason = event.input[3]; - - if(event.allChannels.hasOwnProperty(channelName)) { - var channel = event.allChannels[channelName]; - if(channel.nicks.hasOwnProperty(nick)) { - var ops = []; - for(var possibOps in channel.nicks) { - if(channel.nicks[possibOps].op == true) { - ops.push(possibOps); - } - } - - // Does the channel have an admin channel? - if(event.allChannels.hasOwnProperty('#' + channelName)) { - ops.push('#' + channelName); - } - - for(var i=0;i 0)) { - winner = candidates[i]; - winnerDistance = distance; - } - } - - if(winnerDistance < Math.ceil(winner.length * 1.33)) { - if(winner !== correction) { - var fix = last[event.channel.name][candidate].replace(winner, correction); - if (/^.ACTION/.test(fix)) { - fix = fix.replace(/^.ACTION/, '/me'); - } - last[event.channel.name][candidate] = fix; - var output = { - 'fix': fix, - 'correcter': event.user, - 'candidate': candidate - }; - output_callback(output); - } - } - } - - return { - 'name': 'spelling', - 'ignorable': true, - - 'listener': function(event) { - var q = event.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3); - var otherQ = event.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4); - if(q) { - correct(event, q[1] || q[2], event.user, function (e) { - event.reply(dbot.t('spelling_self', e)); - }); - } else if(otherQ) { - correct(event, otherQ[2] || otherQ[3], otherQ[1], function (e) { - event.reply(dbot.t('spelling_other', e)); - }); - } else { - if(last.hasOwnProperty(event.channel.name)) { - last[event.channel.name][event.user] = event.message; - } else { - last[event.channel.name] = { }; - last[event.channel.name][event.user] = event.message; - } - } - }, - 'on': 'PRIVMSG' - } -} - -exports.fetch = function(dbot) { - return spelling(dbot); -}; diff --git a/modules/web.js b/modules/web.js deleted file mode 100644 index 1be542a..0000000 --- a/modules/web.js +++ /dev/null @@ -1,130 +0,0 @@ -var express = require('express'); - -var webInterface = function(dbot) { - var pub = 'public'; - var app = express.createServer(); - - app.use(express.compiler({ src: pub, enable: ['sass'] })); - app.use(express.static(pub)); - app.set('view engine', 'jade'); - - app.get('/', function(req, res) { - res.render('index', { 'name': dbot.name }); - }); - - app.get('/connections', function(req, res) { - var connections = Object.keys(dbot.instance.connections); - res.render('connections', { 'name': dbot.name, 'connections': connections }); - }); - - app.get('/channels/:connection', function(req, res) { - var connection = req.params.connection; - if(dbot.instance.connections.hasOwnProperty(connection)) { - var channels = Object.keys(dbot.instance.connections[connection].channels); - res.render('channels', { 'name': dbot.name, 'connection': connection, 'channels': channels}); - } else { - res.render('error', { 'name': dbot.name, 'message': 'No such connection.' }); - } - }); - - app.get('/users/:connection/:channel', function(req, res) { - var connection = req.params.connection; - var channel = '#' + req.params.channel; - var connections = dbot.instance.connections; - - if(connections.hasOwnProperty(connection) && - connections[connection].channels.hasOwnProperty(channel)) { - var nicks = Object.keys(connections[connection].channels[channel].nicks); - res.render('users', { 'name': dbot.name, 'connection': connection, - 'channel': channel, 'nicks': nicks }); - } else { - res.render('error', { 'name': dbot.name, 'message': 'No such connection or channel.' }); - } - }); - - app.get('/user/:connection/:channel/:user', function(req, res) { - var connection = req.params.connection; - var channel = '#' + req.params.channel; - var user = dbot.cleanNick(req.params.user); - - var quoteCount = 'no'; - if(dbot.db.quoteArrs.hasOwnProperty(user)) { - var quoteCount = dbot.db.quoteArrs[user].length; - } - - if(!dbot.db.kicks.hasOwnProperty(req.params.user)) { - var kicks = '0'; - } else { - var kicks = dbot.db.kicks[req.params.user]; - } - - if(!dbot.db.kickers.hasOwnProperty(req.params.user)) { - var kicked = '0'; - } else { - var kicked = dbot.db.kickers[req.params.user]; - } - - res.render('user', { 'name': dbot.name, 'user': req.params.user, - 'channel': channel, 'connection': connection, 'cleanUser': user, - 'quotecount': quoteCount, 'kicks': kicks, 'kicked': kicked }); - }); - - // Lists the quote categories - app.get('/quotes', function(req, res) { - res.render('quotelist', { 'name': dbot.name, 'quotelist': Object.keys(dbot.db.quoteArrs) }); - }); - - // Lists quotes in a category - app.get('/quotes/:key', function(req, res) { - var key = req.params.key.toLowerCase(); - if(dbot.db.quoteArrs.hasOwnProperty(key)) { - res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[key], locals: { 'url_regex': RegExp.prototype.url_regex() } }); - } else { - res.render('error', { 'name': dbot.name, 'message': 'No quotes under that key.' }); - } - }); - - // Load random quote category page - app.get('/rq', function(req, res) { - var rCategory = Object.keys(dbot.db.quoteArrs).random(); - res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[rCategory], locals: { 'url_regex': RegExp.prototype.url_regex() } }); - }); - - // Lists all of the polls - app.get('/polls', function(req, res) { - res.render('polllist', { 'name': dbot.name, 'polllist': Object.keys(dbot.db.polls) }); - }); - - // Shows the results of a poll - app.get('/polls/:key', function(req, res) { - var key = req.params.key.toLowerCase(); - if(dbot.db.polls.hasOwnProperty(key) && dbot.db.polls[key].hasOwnProperty('description')) { - // tally the votes - var totalVotes = 0; - for( var v in dbot.db.polls[key].votes ) { - var N = Number(dbot.db.polls[key].votes[v]); - if( !isNaN(N) ) { - totalVotes += N; - } - } - res.render('polls', { 'name': dbot.name, 'description': dbot.db.polls[key].description, 'votees': Object.keys(dbot.db.polls[key].votees), 'options': dbot.db.polls[key].votes, locals: { 'totalVotes': totalVotes, 'url_regex': RegExp.prototype.url_regex() } }); - } else { - res.render('error', { 'name': dbot.name, 'message': 'No polls under that key.' }); - } - }); - - app.listen(dbot.webPort); - - return { - 'name': 'web', - 'ignorable': false, - - 'onDestroy': function() { - app.close(); - } - }; -}; - -exports.fetch = function(dbot) { - return webInterface(dbot); -}; diff --git a/modules/youare.js b/modules/youare.js deleted file mode 100644 index ddb25e0..0000000 --- a/modules/youare.js +++ /dev/null @@ -1,19 +0,0 @@ -var youAre = function(dbot) { - return { - 'name': 'youare', - 'ignorable': false, - - 'listener': function(event) { - var key = event.message.valMatch(/(\bis\b|\bare\b)\s+([\w\s\d]*?)(\s+)?(,|\.|\band\b|$)/, 5); - - if(key && key[2] != "" && Number.prototype.chanceIn(1, 100) && event.user != 'aisbot') { - event.reply(event.user + ': You\'re ' + key[2] + '.'); - } - }, - 'on': 'PRIVMSG' - }; -}; - -exports.fetch = function(dbot) { - return youAre(dbot); -}; diff --git a/strings.json b/strings.json index 1ed16e7..7933cc6 100644 --- a/strings.json +++ b/strings.json @@ -130,73 +130,6 @@ "spanish": "¿Querías decir: ", "na'vi": "Srake sweylu nga pamrel sivi: ", "welsh": "A oeddech chi'n feddwl: " - }, - "gpull": { - "english": "Git pulled that shit.", - "spanish": "Hecho git pull en esta mierda.", - "na'vi": "Gìtìl fì'uti stamarsìm.", - "welsh": "Wedi tynnu git yr cach na i gyd" - }, - "reload": { - "english": "Reloaded that shit.", - "spanish": "Recargado esta mierda.", - "na'vi": "Oel fìuti stìyeftxaw.", - "welsh": "Ail-lwytho'r cach na" - }, - "load_module": { - "english": "Loaded new module: {moduleName}", - "spanish": "Cargado módulo nuevo: {moduleName}", - "na'vi": "Oel {moduleName}it amip stìyeftxaw.", - "welsh": "Wedi llwytho modiwl newydd: {moduleName}" - }, - "unload_module": { - "english": "Turned off module: {moduleName}", - "spanish": "Descargado módulo: {moduleName}", - "na'vi": "Oel {moduleName} tswìya'.", - "welsh": "Wedi troi ffwrdd y modiwl: {moduleName}" - }, - "unload_error": { - "english": "{moduleName} isn't loaded. Idiot.", - "spanish": "{moduleName} no está cargado. Idiota.", - "na'vi": "Oel {moduleName}it omum. Nga skxawng lu.", - "welsh": "Di {moduleName} ddim wedi llwytho. Twpsyn" - }, - "banned": { - "english": "{user} banned from {command}", - "spanish": "{user} está prohibido de usar {command}", - "na'vi": "{command}ìri {user} ke tung.", - "welsh": "{user} wedi ei gohurio o {command}" - }, - "unbanned": { - "english": "{user} unbanned from {command}", - "spanish": "{user} no está prohibido de user {command}", - "na'vi": "{command}ìri {user} tung set.", - "welsh": "{user} wedi ei dad-wahardd o {command}" - }, - "unban_error": { - "english": "{user} wasn't banned from that command, fool.", - "spanish": "{user} no fue prohibido de esta instrucción, tont@.", - "na'vi": "{user} fìtsu'oti tamung srekrr, nga skxawng lu.", - "welsh": "Nid oedd {user} wedi ei wahardd o'r gyrchymun yna, fŵl" - }, - "modehate": { - "english": "Hating on {user}", - "spanish": "Odiando a {user}", - "na'vi": "Oel {user}it vere'kì.", - "welsh": "Casau ar {user}" - }, - "unmodehate": { - "english": "No longer hating on {user}", - "spanish": "Ni siquera odiando a {user}", - "na'vi": "Oel {user}it ke vere'kì.", - "welsh": "Ddim yn casau ar {user} bellach" - }, - "qlock": { - "english": "Locked quote category: {category}", - "spanish": "Cerrado la categoría: {category}", - "na'vi": "{category}ìri oel 'upxareti fmoli", - "welsh": "Categori wedi cloi: {category}" - }, "spelling_self": { "english": "{correcter} meant: {fix}", "spanish": "{correcter} quería decir: {fix}", @@ -287,18 +220,6 @@ "na'vi": "{category} ({needle}): '{quote}' [kum a{matches}]", "welsh": "{category} ({needle}): '{quote}' [{matches} canlyniad]" }, - "join": { - "english": "Joined {channel}", - "spanish" : "Entrado en {channel}", - "na'vi": "fpxäkìm {channel}(nemfa)", - "welsh": "Wedi ymuno {channel}" - }, - "part": { - "english": "Left {channel}", - "spanish" : "Abandonada {channel}", - "na'vi": "Hum {channel}", - "welsh": "Wedi gadael {channel}" - }, "newpoll_usage": { "english": "Usage: ~newpoll name [options=opt1,opt2,opt3] description", "spanish" : "Modo de empleo: ~newpoll nombre [options=opción1,opción2,opción3] descripción", From 3a58f6b8b100b28c5955b7c41b5fdda56a1a40ca Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:26:29 +0000 Subject: [PATCH 04/27] moved strings for command --- modules/admin/strings.json | 6 ++++++ modules/command/strings.json | 14 ++++++++++++++ strings.json | 18 ------------------ 3 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 modules/command/strings.json diff --git a/modules/admin/strings.json b/modules/admin/strings.json index 8ecacd0..553a096 100644 --- a/modules/admin/strings.json +++ b/modules/admin/strings.json @@ -64,5 +64,11 @@ "spanish": "Cerrado la categoría: {category}", "na'vi": "{category}ìri oel 'upxareti fmoli", "welsh": "Categori wedi cloi: {category}" + }, + "module_load_error": { + "english": "Failed to load module: {moduleName}", + "spanish": "No se pudó cargar el módulo: {moduleName}", + "na'vi": "Oeru Oel {moduleName}it sung.", + "welsh": "Wedi methu a llwytho modiwl: {moduleName}" } } diff --git a/modules/command/strings.json b/modules/command/strings.json new file mode 100644 index 0000000..47e1b11 --- /dev/null +++ b/modules/command/strings.json @@ -0,0 +1,14 @@ +{ + "command_ban": { + "english": "{user} is banned from using this command. Commence incineration.", + "spanish": "{user} está prohibido de usar esta instrucción. Comenzar incineración.", + "na'vi": "Tsu'ori {user} ke tung. Nga skxawng lu.", + "welsh": "Mae {user} wedi ei gohurio gan ddefnyddio'r gorchymun yma. Cychwyn orfflosgiad" + }, + "syntax_error": { + "english": "Invalid syntax. Initiate incineration.", + "spanish": "Sintaxis no válida. Iniciar incineración.", + "na'vi": "Ngeyä pamrel keyawr lu. Nga skxawng lu.", + "welsh": "Cystrawen annilys. Cychwyn orfflosgiad" + } +} diff --git a/strings.json b/strings.json index 7933cc6..dd5b5ac 100644 --- a/strings.json +++ b/strings.json @@ -1,16 +1,4 @@ { - "syntax_error": { - "english": "Invalid syntax. Initiate incineration.", - "spanish": "Sintaxis no válida. Iniciar incineración.", - "na'vi": "Ngeyä pamrel keyawr lu. Nga skxawng lu.", - "welsh": "Cystrawen annilys. Cychwyn orfflosgiad" - }, - "module_load_error": { - "english": "Failed to load module: {moduleName}", - "spanish": "No se pudó cargar el módulo: {moduleName}", - "na'vi": "Oeru Oel {moduleName}it sung.", - "welsh": "Wedi methu a llwytho modiwl: {moduleName}" - }, "category_not_found": { "english": "Nobody loves {category}", "spanish": "Nadie ama a {category}", @@ -119,12 +107,6 @@ "na'vi": "Kea seng amek. Nga skxawng lu.", "welsh": "Dim categoriau dyfyniadau gwag. Cychwyn orfflosgiad" }, - "command_ban": { - "english": "{user} is banned from using this command. Commence incineration.", - "spanish": "{user} está prohibido de usar esta instrucción. Comenzar incineración.", - "na'vi": "Tsu'ori {user} ke tung. Nga skxawng lu.", - "welsh": "Mae {user} wedi ei gohurio gan ddefnyddio'r gorchymun yma. Cychwyn orfflosgiad" - }, "correction": { "english": "Did you mean: ", "spanish": "¿Querías decir: ", From 5a75c63672da6b2d0b5df408cfadb041b58edf02 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:26:59 +0000 Subject: [PATCH 05/27] removed drama because why bother --- modules/drama/drama.js | 96 ------------------------------------------ 1 file changed, 96 deletions(-) delete mode 100644 modules/drama/drama.js diff --git a/modules/drama/drama.js b/modules/drama/drama.js deleted file mode 100644 index fc9aa3a..0000000 --- a/modules/drama/drama.js +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Module Name: Drama - * Description: Experimental, you probably don't want it. - */ -var brain = require('brain'); - -var drama = function(dbot) { - var dbot = dbot; - var last = {}; - var options = { - 'backend': { - 'type': 'Redis', - 'options': { - 'hostname': 'localhost', - 'port': 6379, - 'name': 'dbotdrama' - } - }, - - 'thresholds': { - 'drama': 3, - 'beinganasshole': 3, - 'sd': 3, // self depracating - 'normal': 1 - }, - - 'def': 'normal' - }; - var bayes = new brain.BayesianClassifier(options); - - var commands = { - '~train': function(event) { - if(dbot.admin.include(event.user)) { - bayes.train(last[event.params[1]][event.params[2]], event.params[3]); - event.reply('Last thing ' + event.params[2] + ' said in ' + - event.params[1] + ' (' + last[event.params[1]][event.params[2]] + ') classified as \'' + event.params[3] + '\''); - } - }, - - '~rtrain': function(event) { - if(dbot.admin.include(event.user)) { - var category = event.params[1]; - event.params.splice(0, 2); - var msg = event.params.join(' '); - bayes.train(msg, category); - event.reply('\'' + msg + '\' classified as \'' + category + '\''); - } - }, - - '~classify': function(event) { - event.params.splice(0, 1); - var msg = event.params.join(' '); - bayes.classify(msg, function(category) { - event.reply('Classified as: ' + category + '!'); - }.bind(this)); - } - } - - return { - 'name': 'drama', - 'ignorable': false, - 'commands': commands, - - 'listener': function(data) { - var category = bayes.classify(data.message, function(category) { - if(category !== 'normal') { - if(category === 'beinganasshole') { - if(dbot.db.drama.beinganasshole.hasOwnProperty(event.user)) { - dbot.db.drama.beinganasshole[event.user]++; - } else { - dbot.db.drama.beinganasshole[event.user] = 1; - } - } else if(category === 'sd') { - if(dbot.db.drama.sd.hasOwnProperty(event.user)) { - dbot.db.drama.sd[event.user]++; - } else { - dbot.db.drama.sd[event.user] = 1; - } - } - } - }.bind(this)); - - if(last.hasOwnProperty(event.channel)) { - last[event.channel][event.user] = data.message; - } else { - last[event.channel] = { }; - last[event.channel][event.user] = data.message; - } - }, - 'on': 'PRIVMSG' - }; -} - -exports.fetch = function(dbot) { - return drama(dbot); -}; From 6d52d5a2b4b78ccb265eabec878c1e0d8335417e Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:29:20 +0000 Subject: [PATCH 06/27] moved ignore strings --- modules/ignore/strings.json | 44 +++++++++++++++++++++++++++++++++++++ strings.json | 42 ----------------------------------- 2 files changed, 44 insertions(+), 42 deletions(-) create mode 100644 modules/ignore/strings.json diff --git a/modules/ignore/strings.json b/modules/ignore/strings.json new file mode 100644 index 0000000..e926a7a --- /dev/null +++ b/modules/ignore/strings.json @@ -0,0 +1,44 @@ +{ + "ignore_usage": { + "english": "{user}: Usage: ~ignore [module]. Modules you can ignore are: {modules}.", + "spanish": "{user}: Modo de empleo: ~ignore [módulo]. Módulos que tú puedes ignorar son: {modules}.", + "na'vi": "{user}: Sar: ~ignore ['u]. U, nga ke tìng mikyun: {modules}.", + "welsh": "{user}: Defnydd: ~ignore [modiwl]. Modiwlau a allech anwybyddu yw: {modules}." + }, + "already_ignoring": { + "english": "{user}: You're already ignoring that module.", + "spanish": "{user}: Ya ignoras este módulo.", + "na'vi": "{user}: 'uri nga ke tìng mikyun srekrr.", + "welsh": "{user}: Mi rwyt ti'n anwybyddu'r modiwl yna'n barod." + }, + "ignored": { + "english": "{user}: Now ignoring {module}.", + "spanish": "{user}: Estás ignorando {module}.", + "na'vi": "{user}: Nga ke terìng mikyun {module}ne set.", + "welsh": "{user}: Nawr yn anwybyddu {module}" + }, + "invalid_ignore": { + "english": "{user}: That isn't a valid module name.", + "spanish": "{user}: Ese no es un nombre de un módulo valido.", + "na'vi": "{user}: Tsatstxo eyawr ke lu.", + "welsh": "{user}: Nid oedd hwna'n modiwl dilys" + }, + "unignore_usage": { + "english": "{user}: Usage: ~unignore [module]. Modules you are currently ignoring: {modules}.", + "spanish": "{user}: Modo de empleo: ~unignore [módulo]. Módulos que ignoras ahora mismo: {modules}.", + "na'vi": "{user}: Sar: ~unignore ['u]. Uri, nga ke terìng mikyun: {modules}.", + "welsh": "{user}: Defnydd ~unignore [modiwl]. Modiwlau rydech yn anwybyddu ar hyn o bryd: {modules}" + }, + "invalid_unignore": { + "english": "{user}: You're not ignoring that module or it doesn't exist.", + "spanish": "{user}: No ignoras este módulo o no existe.", + "na'vi":"{user}: Nga terìng mikyun fu fì'ul fìtsengit ke tok.", + "welsh": "{user}: Nid wyt ti'n anwybyddu'r modiwl yna neu nid yw e'n bodoli" + }, + "unignored": { + "english": "{user}: No longer ignoring {module}.", + "spanish": "{user}: Ya no ignoras {module}.", + "na'vi": "{user}: Nga terìng mikyun {module}ne set", + "welsh": "{user}: Ddim yn anwybyddu {module} bellach" + } +} diff --git a/strings.json b/strings.json index dd5b5ac..18f9142 100644 --- a/strings.json +++ b/strings.json @@ -136,48 +136,6 @@ "na'vi": "Fya'o apup {user}ta: ", "welsh": "Dolen wedi ei fyrhau can {user}: " }, - "ignore_usage": { - "english": "{user}: Usage: ~ignore [module]. Modules you can ignore are: {modules}.", - "spanish": "{user}: Modo de empleo: ~ignore [módulo]. Módulos que tú puedes ignorar son: {modules}.", - "na'vi": "{user}: Sar: ~ignore ['u]. U, nga ke tìng mikyun: {modules}.", - "welsh": "{user}: Defnydd: ~ignore [modiwl]. Modiwlau a allech anwybyddu yw: {modules}." - }, - "already_ignoring": { - "english": "{user}: You're already ignoring that module.", - "spanish": "{user}: Ya ignoras este módulo.", - "na'vi": "{user}: 'uri nga ke tìng mikyun srekrr.", - "welsh": "{user}: Mi rwyt ti'n anwybyddu'r modiwl yna'n barod." - }, - "ignored": { - "english": "{user}: Now ignoring {module}.", - "spanish": "{user}: Estás ignorando {module}.", - "na'vi": "{user}: Nga ke terìng mikyun {module}ne set.", - "welsh": "{user}: Nawr yn anwybyddu {module}" - }, - "invalid_ignore": { - "english": "{user}: That isn't a valid module name.", - "spanish": "{user}: Ese no es un nombre de un módulo valido.", - "na'vi": "{user}: Tsatstxo eyawr ke lu.", - "welsh": "{user}: Nid oedd hwna'n modiwl dilys" - }, - "unignore_usage": { - "english": "{user}: Usage: ~unignore [module]. Modules you are currently ignoring: {modules}.", - "spanish": "{user}: Modo de empleo: ~unignore [módulo]. Módulos que ignoras ahora mismo: {modules}.", - "na'vi": "{user}: Sar: ~unignore ['u]. Uri, nga ke terìng mikyun: {modules}.", - "welsh": "{user}: Defnydd ~unignore [modiwl]. Modiwlau rydech yn anwybyddu ar hyn o bryd: {modules}" - }, - "invalid_unignore": { - "english": "{user}: You're not ignoring that module or it doesn't exist.", - "spanish": "{user}: No ignoras este módulo o no existe.", - "na'vi":"{user}: Nga terìng mikyun fu fì'ul fìtsengit ke tok.", - "welsh": "{user}: Nid wyt ti'n anwybyddu'r modiwl yna neu nid yw e'n bodoli" - }, - "unignored": { - "english": "{user}: No longer ignoring {module}.", - "spanish": "{user}: Ya no ignoras {module}.", - "na'vi": "{user}: Nga terìng mikyun {module}ne set", - "welsh": "{user}: Ddim yn anwybyddu {module} bellach" - }, "command_typo": { "english": "Did you mean '{command}'? Learn to type.", "spanish": "¿Querías decir '{command}'? Aprende escribir.", From 4941e50d060adc3ab68c94e1c485a074fc1f8061 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:31:20 +0000 Subject: [PATCH 07/27] whoops karma isnt supposed to be in this tree --- modules/karma/karma.js | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 modules/karma/karma.js diff --git a/modules/karma/karma.js b/modules/karma/karma.js deleted file mode 100644 index db569c3..0000000 --- a/modules/karma/karma.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Module Name: Karma - * Description: Automatically shorten link over a certain length and post the - * short link to the channel. - */ -var = function(dbot) { - return { - From de84491975358ca74a5f3c366016477aa94e7b04 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:32:59 +0000 Subject: [PATCH 08/27] moved kick strings --- modules/kick/strings.json | 14 ++++++++++++++ strings.json | 14 +------------- 2 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 modules/kick/strings.json diff --git a/modules/kick/strings.json b/modules/kick/strings.json new file mode 100644 index 0000000..0fe8376 --- /dev/null +++ b/modules/kick/strings.json @@ -0,0 +1,14 @@ +{ + "user_kicks": { + "english": "{user} has been kicked {kicks} times and has kicked people {kicked} times.", + "spanish": "Se ha expulsado {user} {kicks} veces y {user} ha expulsado personas {kicked} veces.", + "na'vi": "Tuteol {user}it tsrame'i {kicks} hìmtxan ulte sute tsrame'i {kicked} hìmtxan.", + "welsh": "Cafwyd {user} ei gicio {kicks} gwaith ac wedi cicio pobl {kicked} gwaith." + }, + "kicked_dbot": { + "english": "Thou shalt not kick {botname}", + "spanish": "No expulsás {botname}", + "na'vi": "Ngal {botname}it ke tsun tsrive'i", + "welsh": "Ni ddylech cicio {botname}" + } +} diff --git a/strings.json b/strings.json index 18f9142..6c8bbb5 100644 --- a/strings.json +++ b/strings.json @@ -142,19 +142,7 @@ "na'vi": "Sweylu nga pamrel sivi '{command}' srak? Sweylu ngeyä pamrel livu eyawr.", "welsh": "A oeddech chi'n feddwl '{command}'? Dysgwch sut i teipio." }, - "user_kicks": { - "english": "{user} has been kicked {kicks} times and has kicked people {kicked} times.", - "spanish": "Se ha expulsado {user} {kicks} veces y {user} ha expulsado personas {kicked} veces.", - "na'vi": "Tuteol {user}it tsrame'i {kicks} hìmtxan ulte sute tsrame'i {kicked} hìmtxan.", - "welsh": "Cafwyd {user} ei gicio {kicks} gwaith ac wedi cicio pobl {kicked} gwaith." - }, - "kicked_dbot": { - "english": "Thou shalt not kick {botname}", - "spanish": "No expulsás {botname}", - "na'vi": "Ngal {botname}it ke tsun tsrive'i", - "welsh": "Ni ddylech cicio {botname}" - }, - "search_results": { + "search_results": { "english": "{category} ({needle}): '{quote}' [{matches} results]", "spanish" : "{category} ({needle}): '{quote}' [{matches} resultados]", "na'vi": "{category} ({needle}): '{quote}' [kum a{matches}]", From 34e377f3857bf29292268709eb7ab595df1fc2fc Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:37:05 +0000 Subject: [PATCH 09/27] moved poll strings --- modules/poll/strings.json | 87 ++++++++++++++++++++++++++++++++++++ strings.json | 93 +-------------------------------------- 2 files changed, 88 insertions(+), 92 deletions(-) create mode 100644 modules/poll/strings.json diff --git a/modules/poll/strings.json b/modules/poll/strings.json new file mode 100644 index 0000000..459ea98 --- /dev/null +++ b/modules/poll/strings.json @@ -0,0 +1,87 @@ +{ + "newpoll_usage": { + "english": "Usage: ~newpoll name [options=opt1,opt2,opt3] description", + "spanish" : "Modo de empleo: ~newpoll nombre [options=opción1,opción2,opción3] descripción", + "na'vi": "Usage: ~newpoll tstxo [sìftxey=tìfxey1,tìfxey2,fìfxey3] tìsla'tsu", + "welsh": "Defnydd: ~newpoll enw [optiynau=opt1,opt2,op3] disgrifiad" + }, + "poll_exists": { + "english": "Poll '{name}' already exists.", + "spanish" : "Votación '{name}' ya existe.", + "na'vi": "sìpawm sna'o '{name}' fkeytok srekrr.", + "welsh": "Mae'r pôl {name} bodoli'n barod" + }, + "poll_created": { + "english": "Poll '{name}' created ({description}). Cast thy votations! - {url}", + "spanish" : "Votación '{name}' creado ({description}). ¡Emited sus votas! - {url}", + "na'vi": "sìpawm sna'o '{name}' ngìyop ({description}). Nga tìpe'unit Pe'eiun - {url}" + }, + "poll_describe": { + "english": "{name}: {description} - {url}" + }, + "changed_vote": { + "english": "{user} changed their vote in {poll} to '{vote}' ({count}).", + "spanish" : "{user} cambió su voto en {poll} a '{vote}' ({count}).", + "na'vi": "{user} lìyatem ngeyä tìpe'un {poll}mì, ngeyä tìpe'un amip '{vote}'({count}) lu.", + "welsh": "Newidiodd {user} eu pleidlais yn {poll} i '{vote}' ({count})." + }, + "voted": { + "english": "{user} voted for '{vote}' in {poll} ({count}).", + "spanish" : "{user} votó para '{vote}' en {poll} ({count}).", + "na'vi": "'{vote}'ìri {user} pìye'un {poll}mì ({count}).", + "welsh": "Pledleisiodd {user} am '{vote}' yn {poll} ({count})." + }, + "invalid_vote": { + "english": "Invalid vote: {vote}", + "spanish" : "Vota inválida: {vote}", + "na'vi": "Ngeyä tìpe'un keyawr lu ({vote}).", + "welsh": "Pleidlais annilys: {vote}" + }, + "poll_unexistent": { + "english": "Poll '{name}' doesn't exist.", + "spanish" : "Votación '{name}' no existe.", + "na'vi": "sìpawm sna'o '{name}' ke fkeytok.", + "welsh": "Nid yw pôl '{name}' yn bodoli" + }, + "option_added": { + "english": "{user}: '{option}' added to '{name}'.", + "spanish" : "{user}: '{option}' añadido a '{name}'.", + "na'vi": "'{name}'ur {user}ìl '{option}'it sung.", + "welsh": "{user}: Ychwanegwyd '{option}' i '{name}'" + }, + "option_exists": { + "english": "{user}: '{option}' already exists in '{name}'.", + "spanish" : "{user}: '{option}' ya existe en '{name}'.", + "na'vi": "{user}: '{option}' fkeytok srekrr '{name}'mì.", + "welsh": "{user}: Mae '{option}' yn bodoli'n barod yn '{name}'." + }, + "not_poll_owner": { + "english": "{user}: You don't own the '{name}' poll.", + "spanish" : "{user}: La votación '{name}' no es tuyo.", + "na'vi": "{user}: ngaru '{name}' sìpawm sna'o ke lu.", + "welsh": "{user}: Nid ydech chi'n berchen y pôl '{name}'." + }, + "option_removed": { + "english": "{user}: '{option}' removed from '{name}'", + "spanish" : "{user}: '{option}' eliminado de '{name}'", + "na'vi": "{user}: '{option}'it 'aku '{name}'ta", + "welsh": "{user}: '{option}' wedi ei ddileu o '{name}'" + }, + "av_voted": { + "english": "{user} voted '{vote}' in {poll}.", + "spanish": "{user} votó '{vote}' en {poll}.", + "na'vi": "{user}ìl '{vote}'it pìye'un '{poll}'mì.", + "welsh": "Pledleisiodd {user} am '{vote}' yn {poll}" + }, + "av_changed_vote": { + "english": "{user} changed their vote in {poll} to '{vote}'.", + "spanish" : "{user} cambió su voto en {poll} a '{vote}'.", + "na'vi": "{user}ìl lìyatem ngeyä tìpa'unit '{poll}'mì, ngeyä tìpe'un '{vote} lu set.", + "welsh": "Newidiodd {user} eu pleidlais yn {poll} i '{vote}'" + }, + "count": { + "english": "The running-order of poll '{poll}' ({description}) is: {places}.", + "na'vi": "Sute tsnì pole'un '{poll}'mì ({description}) lu: {places}.", + "welsh": "Trefn yr pôl '{poll}' ({description}) yw: {places}" + } +} diff --git a/strings.json b/strings.json index 6c8bbb5..67cd4ca 100644 --- a/strings.json +++ b/strings.json @@ -130,12 +130,6 @@ "na'vi": "Fya'o {category}ne - {url}", "welsh": "Dolen i {category} - {url}" }, - "shorten_link": { - "english": "Shortened link from {user}: ", - "spanish": "Enlace corto de {user}: ", - "na'vi": "Fya'o apup {user}ta: ", - "welsh": "Dolen wedi ei fyrhau can {user}: " - }, "command_typo": { "english": "Did you mean '{command}'? Learn to type.", "spanish": "¿Querías decir '{command}'? Aprende escribir.", @@ -148,92 +142,7 @@ "na'vi": "{category} ({needle}): '{quote}' [kum a{matches}]", "welsh": "{category} ({needle}): '{quote}' [{matches} canlyniad]" }, - "newpoll_usage": { - "english": "Usage: ~newpoll name [options=opt1,opt2,opt3] description", - "spanish" : "Modo de empleo: ~newpoll nombre [options=opción1,opción2,opción3] descripción", - "na'vi": "Usage: ~newpoll tstxo [sìftxey=tìfxey1,tìfxey2,fìfxey3] tìsla'tsu", - "welsh": "Defnydd: ~newpoll enw [optiynau=opt1,opt2,op3] disgrifiad" - }, - "poll_exists": { - "english": "Poll '{name}' already exists.", - "spanish" : "Votación '{name}' ya existe.", - "na'vi": "sìpawm sna'o '{name}' fkeytok srekrr.", - "welsh": "Mae'r pôl {name} bodoli'n barod" - }, - "poll_created": { - "english": "Poll '{name}' created ({description}). Cast thy votations! - {url}", - "spanish" : "Votación '{name}' creado ({description}). ¡Emited sus votas! - {url}", - "na'vi": "sìpawm sna'o '{name}' ngìyop ({description}). Nga tìpe'unit Pe'eiun - {url}" - }, - "poll_describe": { - "english": "{name}: {description} - {url}" - }, - "changed_vote": { - "english": "{user} changed their vote in {poll} to '{vote}' ({count}).", - "spanish" : "{user} cambió su voto en {poll} a '{vote}' ({count}).", - "na'vi": "{user} lìyatem ngeyä tìpe'un {poll}mì, ngeyä tìpe'un amip '{vote}'({count}) lu.", - "welsh": "Newidiodd {user} eu pleidlais yn {poll} i '{vote}' ({count})." - }, - "voted": { - "english": "{user} voted for '{vote}' in {poll} ({count}).", - "spanish" : "{user} votó para '{vote}' en {poll} ({count}).", - "na'vi": "'{vote}'ìri {user} pìye'un {poll}mì ({count}).", - "welsh": "Pledleisiodd {user} am '{vote}' yn {poll} ({count})." - }, - "invalid_vote": { - "english": "Invalid vote: {vote}", - "spanish" : "Vota inválida: {vote}", - "na'vi": "Ngeyä tìpe'un keyawr lu ({vote}).", - "welsh": "Pleidlais annilys: {vote}" - }, - "poll_unexistent": { - "english": "Poll '{name}' doesn't exist.", - "spanish" : "Votación '{name}' no existe.", - "na'vi": "sìpawm sna'o '{name}' ke fkeytok.", - "welsh": "Nid yw pôl '{name}' yn bodoli" - }, - "option_added": { - "english": "{user}: '{option}' added to '{name}'.", - "spanish" : "{user}: '{option}' añadido a '{name}'.", - "na'vi": "'{name}'ur {user}ìl '{option}'it sung.", - "welsh": "{user}: Ychwanegwyd '{option}' i '{name}'" - }, - "option_exists": { - "english": "{user}: '{option}' already exists in '{name}'.", - "spanish" : "{user}: '{option}' ya existe en '{name}'.", - "na'vi": "{user}: '{option}' fkeytok srekrr '{name}'mì.", - "welsh": "{user}: Mae '{option}' yn bodoli'n barod yn '{name}'." - }, - "not_poll_owner": { - "english": "{user}: You don't own the '{name}' poll.", - "spanish" : "{user}: La votación '{name}' no es tuyo.", - "na'vi": "{user}: ngaru '{name}' sìpawm sna'o ke lu.", - "welsh": "{user}: Nid ydech chi'n berchen y pôl '{name}'." - }, - "option_removed": { - "english": "{user}: '{option}' removed from '{name}'", - "spanish" : "{user}: '{option}' eliminado de '{name}'", - "na'vi": "{user}: '{option}'it 'aku '{name}'ta", - "welsh": "{user}: '{option}' wedi ei ddileu o '{name}'" - }, - "av_voted": { - "english": "{user} voted '{vote}' in {poll}.", - "spanish": "{user} votó '{vote}' en {poll}.", - "na'vi": "{user}ìl '{vote}'it pìye'un '{poll}'mì.", - "welsh": "Pledleisiodd {user} am '{vote}' yn {poll}" - }, - "av_changed_vote": { - "english": "{user} changed their vote in {poll} to '{vote}'.", - "spanish" : "{user} cambió su voto en {poll} a '{vote}'.", - "na'vi": "{user}ìl lìyatem ngeyä tìpa'unit '{poll}'mì, ngeyä tìpe'un '{vote} lu set.", - "welsh": "Newidiodd {user} eu pleidlais yn {poll} i '{vote}'" - }, - "count": { - "english": "The running-order of poll '{poll}' ({description}) is: {places}.", - "na'vi": "Sute tsnì pole'un '{poll}'mì ({description}) lu: {places}.", - "welsh": "Trefn yr pôl '{poll}' ({description}) yw: {places}" - }, - "url": { + "url": { "english": "http://{host}:{port}/{path}" } } From dfdcb0d3591a8e0cbdeb4324ed05e85f9a62e4c5 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:42:06 +0000 Subject: [PATCH 10/27] moved quotes strings. removed qprune because it is not needed anymore --- modules/quotes/quotes.js | 17 ----- modules/quotes/strings.json | 110 +++++++++++++++++++++++++++++++ strings.json | 128 +----------------------------------- 3 files changed, 111 insertions(+), 144 deletions(-) create mode 100644 modules/quotes/strings.json diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index 35a8765..479a9f2 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -193,23 +193,6 @@ var quotes = function(dbot) { event.reply(dbot.t('category_not_found')); } }, - - '~qprune': function(event) { - var pruned = [] - for(key in quotes) { - if(quotes.hasOwnProperty(key)) { - if(quotes[key].length == 0) { - delete quotes[key]; - pruned.push(key); - } - } - } - if(pruned.length > 0) { - event.reply(dbot.t('prune', {'categories': pruned.join(", ")})); - } else { - event.reply(dbot.t('no_prune')); - } - } }; commands['~'].regex = [/^~([\d\w\s-]*)/, 2]; diff --git a/modules/quotes/strings.json b/modules/quotes/strings.json new file mode 100644 index 0000000..c013ac3 --- /dev/null +++ b/modules/quotes/strings.json @@ -0,0 +1,110 @@ +{ + "category_not_found": { + "english": "Nobody loves {category}", + "spanish": "Nadie ama a {category}", + "na'vi": "{category} yawne ke lu kawturu.", + "welsh": "Does neb yn caru {category}" + }, + "large_categories": { + "english": "Largest categories: ", + "spanish": "Los categorías más grandes: ", + "na'vi": "U atsawl: ", + "welsh": "Categoriau mwyaf: " + }, + "empty_category": { + "english": "That category has no quotes in. Commence incineration.", + "spanish": "Categoría vacía. Iniciar incineración.", + "na'vi": "Tsauru upxare lu. Nga skxawng lu.", + "welsh": "Nid yw'r categori yna efo dyfyniadau. Cychwyn orfflosgiad" + }, + "no_results": { + "english": "No results found.", + "spanish": "No hubo ningún resultado.", + "na'vi": "Oel kea humit rìmun", + "welsh": "Dim canlyniadau ar gael" + }, + "locked_category": { + "english": "{category} is locked. Commence incineration.", + "spanish": "{category} está cerrada. Comenzar incineración.", + "na'vi": "{category} ke fkeytok set. Nga skxawng lu nafì'u", + "welsh": "Mae {category} wedi cloi. Cychwyn orfflosgiad" + }, + "no_quotes": { + "english": "No quotes exist under {category}", + "spanish": "Ninguna cita existe en {category}", + "na'vi": "Kea upxare fkeytok {category}mì", + "welsh": "Does dim dyfyniadau gan {category}" + }, + "last_removed": { + "english": "Last quote removed from {category}.", + "spanish": "Última cita quitado de {category}.", + "na'vi": "Oel 'upxareti aham 'aku {category}ta", + "welsh": "Dyfyniad olaf wedi ei ddileu o {category}" + }, + "no_recent_adds": { + "english": "No quotes were added recently.", + "spanish": "Ninguna cita fue añadido recientamente.", + "na'vi": "Kea upxareti samung nìfkrr", + "welsh": "Nid oes unrhyw dyfyniadau wedi ei ychwwanegu'n ddiweddar" + }, + "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...", + "na'vi": "Nga Tsasngelit ke zene fpivere'. Sweylu nga fmivi ye'rìn...", + "welsh": "Peidiwch a sbamio hwna. Triwch eto mewn ychydyg funudau..." + }, + "removed_from": { + "english": "'{quote}' removed from {category}", + "spanish": "'{quote}' quitado de {category}", + "na'vi": "'{quote}'(it/ti) 'ìyaku {category}", + "welsh": "'{quote}' wedi ei ddileu o {category}" + }, + "q_not_exist_under": { + "english": "'{quote}' doesn't exist under '{category}'.", + "spanish": "'{quote}' no existe en '{category}'.", + "na'vi": "'{quote}' ke fkeytok '{category}'ta.", + "welsh": "Nid yw '{quote}' yn bodoli yn '{category}'" + }, + "total_quotes": { + "english": "Total quote count: {count}.", + "spanish": "Total de citas: {count}.", + "na'vi": "'upxareri holpxay: {count}.", + "welsh": "Cyfanswm dyfyniadau: {count}." + }, + "quote_exists": { + "english": "Quote already in DB. Initiate incineration.", + "spanish": "Cita ya existe. Iniciar incineración.", + "na'vi": "'Upxarel säomumit fìtsengit tok srekrr. Nga skxawng lu.", + "welsh": "Dyfyniad yn y gronfa ddata yn barod. Cychwyn orfflosgiad" + }, + "quote_saved": { + "english": "Quote saved in '{category}' ({count}).", + "spanish": "Cita guardada en '{category}' ({count}).", + "na'vi": "Oe zayerok '{category}'mì ({count}).", + "welsh": "Dyfyniad wedi ei gadw yn '{category}' ({count})." + }, + "quote_replace": { + "english": "No replacing arrays, you whore.", + "spanish": "No sustituites arrays, hijo de puta.", + "na'vi": "Ngal fìsäomumit ke tsun rivawn. Nga muntxa sayi suteo hrh.", + "welsh": "Peidiwch a newid rhestrau, y cachgi" + }, + "quote_count": { + "english": "{category} has {count} quotes.", + "spanish": "{category} tiene {count} citas.", + "na'vi": "{count}a upxare {category}ur lu.", + "welsh": "{count} dyfyniad yn {category}" + }, + "quote_link": { + "english": "Link to {category} - {url}", + "spanish": "Enlace a {category} - {url}", + "na'vi": "Fya'o {category}ne - {url}", + "welsh": "Dolen i {category} - {url}" + }, + "search_results": { + "english": "{category} ({needle}): '{quote}' [{matches} results]", + "spanish" : "{category} ({needle}): '{quote}' [{matches} resultados]", + "na'vi": "{category} ({needle}): '{quote}' [kum a{matches}]", + "welsh": "{category} ({needle}): '{quote}' [{matches} canlyniad]" + } +} diff --git a/strings.json b/strings.json index 67cd4ca..f1b7781 100644 --- a/strings.json +++ b/strings.json @@ -1,112 +1,4 @@ { - "category_not_found": { - "english": "Nobody loves {category}", - "spanish": "Nadie ama a {category}", - "na'vi": "{category} yawne ke lu kawturu.", - "welsh": "Does neb yn caru {category}" - }, - "large_categories": { - "english": "Largest categories: ", - "spanish": "Los categorías más grandes: ", - "na'vi": "U atsawl: ", - "welsh": "Categoriau mwyaf: " - }, - "empty_category": { - "english": "That category has no quotes in. Commence incineration.", - "spanish": "Categoría vacía. Iniciar incineración.", - "na'vi": "Tsauru upxare lu. Nga skxawng lu.", - "welsh": "Nid yw'r categori yna efo dyfyniadau. Cychwyn orfflosgiad" - }, - "no_results": { - "english": "No results found.", - "spanish": "No hubo ningún resultado.", - "na'vi": "Oel kea humit rìmun", - "welsh": "Dim canlyniadau ar gael" - }, - "locked_category": { - "english": "{category} is locked. Commence incineration.", - "spanish": "{category} está cerrada. Comenzar incineración.", - "na'vi": "{category} ke fkeytok set. Nga skxawng lu nafì'u", - "welsh": "Mae {category} wedi cloi. Cychwyn orfflosgiad" - }, - "no_quotes": { - "english": "No quotes exist under {category}", - "spanish": "Ninguna cita existe en {category}", - "na'vi": "Kea upxare fkeytok {category}mì", - "welsh": "Does dim dyfyniadau gan {category}" - }, - "last_removed": { - "english": "Last quote removed from {category}.", - "spanish": "Última cita quitado de {category}.", - "na'vi": "Oel 'upxareti aham 'aku {category}ta", - "welsh": "Dyfyniad olaf wedi ei ddileu o {category}" - }, - "no_recent_adds": { - "english": "No quotes were added recently.", - "spanish": "Ninguna cita fue añadido recientamente.", - "na'vi": "Kea upxareti samung nìfkrr", - "welsh": "Nid oes unrhyw dyfyniadau wedi ei ychwwanegu'n ddiweddar" - }, - "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...", - "na'vi": "Nga Tsasngelit ke zene fpivere'. Sweylu nga fmivi ye'rìn...", - "welsh": "Peidiwch a sbamio hwna. Triwch eto mewn ychydyg funudau..." - }, - "removed_from": { - "english": "'{quote}' removed from {category}", - "spanish": "'{quote}' quitado de {category}", - "na'vi": "'{quote}'(it/ti) 'ìyaku {category}", - "welsh": "'{quote}' wedi ei ddileu o {category}" - }, - "q_not_exist_under": { - "english": "'{quote}' doesn't exist under '{category}'.", - "spanish": "'{quote}' no existe en '{category}'.", - "na'vi": "'{quote}' ke fkeytok '{category}'ta.", - "welsh": "Nid yw '{quote}' yn bodoli yn '{category}'" - }, - "total_quotes": { - "english": "Total quote count: {count}.", - "spanish": "Total de citas: {count}.", - "na'vi": "'upxareri holpxay: {count}.", - "welsh": "Cyfanswm dyfyniadau: {count}." - }, - "quote_exists": { - "english": "Quote already in DB. Initiate incineration.", - "spanish": "Cita ya existe. Iniciar incineración.", - "na'vi": "'Upxarel säomumit fìtsengit tok srekrr. Nga skxawng lu.", - "welsh": "Dyfyniad yn y gronfa ddata yn barod. Cychwyn orfflosgiad" - }, - "quote_saved": { - "english": "Quote saved in '{category}' ({count}).", - "spanish": "Cita guardada en '{category}' ({count}).", - "na'vi": "Oe zayerok '{category}'mì ({count}).", - "welsh": "Dyfyniad wedi ei gadw yn '{category}' ({count})." - }, - "quote_replace": { - "english": "No replacing arrays, you whore.", - "spanish": "No sustituites arrays, hijo de puta.", - "na'vi": "Ngal fìsäomumit ke tsun rivawn. Nga muntxa sayi suteo hrh.", - "welsh": "Peidiwch a newid rhestrau, y cachgi" - }, - "quote_count": { - "english": "{category} has {count} quotes.", - "spanish": "{category} tiene {count} citas.", - "na'vi": "{count}a upxare {category}ur lu.", - "welsh": "{count} dyfyniad yn {category}" - }, - "prune": { - "english": "Pruning empty quote categories: {categories}", - "spanish": "Reduciendo categorías vacías: {categories}", - "na'vi": "Oel seng amek 'eraku, seng: {categories}", - "welsh": "Tocio categoriau dyfyniadau gwag: {categories}" - }, - "no_prune": { - "english": "No empty quote categories. Commence incineration.", - "spanish": "Ninguna categoría vacía. Comenzar incineracíon.", - "na'vi": "Kea seng amek. Nga skxawng lu.", - "welsh": "Dim categoriau dyfyniadau gwag. Cychwyn orfflosgiad" - }, "correction": { "english": "Did you mean: ", "spanish": "¿Querías decir: ", @@ -124,25 +16,7 @@ "na'vi": "{correcter} fpìl futa sweylu {candiate} pamrel sivi: {fix}", "welsh": "Mae {correcter} yn meddwl bod {candidate} yn feddwl: {fix}" }, - "quote_link": { - "english": "Link to {category} - {url}", - "spanish": "Enlace a {category} - {url}", - "na'vi": "Fya'o {category}ne - {url}", - "welsh": "Dolen i {category} - {url}" - }, - "command_typo": { - "english": "Did you mean '{command}'? Learn to type.", - "spanish": "¿Querías decir '{command}'? Aprende escribir.", - "na'vi": "Sweylu nga pamrel sivi '{command}' srak? Sweylu ngeyä pamrel livu eyawr.", - "welsh": "A oeddech chi'n feddwl '{command}'? Dysgwch sut i teipio." - }, - "search_results": { - "english": "{category} ({needle}): '{quote}' [{matches} results]", - "spanish" : "{category} ({needle}): '{quote}' [{matches} resultados]", - "na'vi": "{category} ({needle}): '{quote}' [kum a{matches}]", - "welsh": "{category} ({needle}): '{quote}' [{matches} canlyniad]" - }, - "url": { + "url": { "english": "http://{host}:{port}/{path}" } } From 96b34c8c31f1b149e27de2a26e540ac6f8a26d3d Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:45:08 +0000 Subject: [PATCH 11/27] Moved poll quotes --- modules/spelling/strings.json | 14 ++++++++++++++ strings.json | 11 ----------- 2 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 modules/spelling/strings.json diff --git a/modules/spelling/strings.json b/modules/spelling/strings.json new file mode 100644 index 0000000..057786e --- /dev/null +++ b/modules/spelling/strings.json @@ -0,0 +1,14 @@ +{ + "spelling_self": { + "english": "{correcter} meant: {fix}", + "spanish": "{correcter} quería decir: {fix}", + "na'vi": "Sweylu {correcter} pamrel sivi: {fix}", + "welsh": "Oedd {correcter} yn feddwl: {fix}" + }, + "spelling_other": { + "english": "{correcter} thinks {candidate} meant: {fix}", + "spanish": "{correcter} piensa que {candidate} queria decir: {fix}", + "na'vi": "{correcter} fpìl futa sweylu {candiate} pamrel sivi: {fix}", + "welsh": "Mae {correcter} yn meddwl bod {candidate} yn feddwl: {fix}" + } +} diff --git a/strings.json b/strings.json index f1b7781..f7eb20c 100644 --- a/strings.json +++ b/strings.json @@ -4,17 +4,6 @@ "spanish": "¿Querías decir: ", "na'vi": "Srake sweylu nga pamrel sivi: ", "welsh": "A oeddech chi'n feddwl: " - "spelling_self": { - "english": "{correcter} meant: {fix}", - "spanish": "{correcter} quería decir: {fix}", - "na'vi": "Sweylu {correcter} pamrel sivi: {fix}", - "welsh": "Oedd {correcter} yn feddwl: {fix}" - }, - "spelling_other": { - "english": "{correcter} thinks {candidate} meant: {fix}", - "spanish": "{correcter} piensa que {candidate} queria decir: {fix}", - "na'vi": "{correcter} fpìl futa sweylu {candiate} pamrel sivi: {fix}", - "welsh": "Mae {correcter} yn meddwl bod {candidate} yn feddwl: {fix}" }, "url": { "english": "http://{host}:{port}/{path}" From cd56a8a197ca60944267ba98e8891ce0db5ac2ce Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 16:53:34 +0000 Subject: [PATCH 12/27] Added usage.json files for all modules --- modules/js/js.js | 2 -- modules/js/usage.json | 4 ++++ modules/poll/poll.js | 8 +------- modules/poll/usage.json | 7 +++++++ modules/quotes/quotes.js | 6 ------ modules/quotes/usage.json | 7 +++++++ modules/report/report.js | 1 - modules/report/usage.json | 3 +++ 8 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 modules/js/usage.json create mode 100644 modules/poll/usage.json create mode 100644 modules/quotes/usage.json create mode 100644 modules/report/usage.json diff --git a/modules/js/js.js b/modules/js/js.js index 3ac75e4..83e1bf0 100644 --- a/modules/js/js.js +++ b/modules/js/js.js @@ -32,8 +32,6 @@ var js = function(dbot) { }; commands['~js'].regex = [/^~js (.*)/, 2]; commands['~ajs'].regex = [/^~ajs (.*)/, 2]; - commands['~js'].usage = '~js [command]'; - commands['~ajs'].usage = '~ajs [command]'; return { 'name': 'js', diff --git a/modules/js/usage.json b/modules/js/usage.json new file mode 100644 index 0000000..a6deb48 --- /dev/null +++ b/modules/js/usage.json @@ -0,0 +1,4 @@ +{ + '~js': '~js [command]', + '~ajs': '~ajs [command]' +} diff --git a/modules/poll/poll.js b/modules/poll/poll.js index 2b82282..a2a6223 100644 --- a/modules/poll/poll.js +++ b/modules/poll/poll.js @@ -214,13 +214,7 @@ var poll = function(dbot) { commands['~vote'].regex = [/~vote ([^ ]+) ([^ ]+)/, 3]; commands['~pdesc'].regex = [/~pdesc ([^ ]+)/, 2]; commands['~count'].regex = [/~count ([^ ]+)/, 2]; - - commands['~newpoll'].usage = '~newpoll [pollname] options=[each,poll,option] [Poll Description]'; - commands['~addoption'].usage = '~addoption [pollname] [newoption]'; - commands['~rmoption'].usage= '~rmoption [pollname] [optiontoremove]'; - commands['~vote'].usage= '~vote [pollname] [option]'; - commands['~pdesc'].usage = '~pdesc [pollname]'; - + return { 'name': 'poll', 'ignorable': true, diff --git a/modules/poll/usage.json b/modules/poll/usage.json new file mode 100644 index 0000000..3fe17f5 --- /dev/null +++ b/modules/poll/usage.json @@ -0,0 +1,7 @@ +{ + '~newpoll': '~newpoll [pollname] options=[each,poll,option] [Poll Description]', + '~addoption': '~addoption [pollname] [newoption]', + '~rmoption': '~rmoption [pollname] [optiontoremove]', + '~vote': '~vote [pollname] [option]', + '~pdesc': '~pdesc [pollname]' +} diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index 479a9f2..582f4e8 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -202,12 +202,6 @@ var quotes = function(dbot) { commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2]; commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; - commands['~q'].usage = '~q [category]'; - commands['~qsearch'].usage = '~qsearch [category]=[search]'; - commands['~rm'].usage = '~rm [category]=[quote to delete]'; - commands['~rmlast'].usage = '~rmlast [category]' - commands['~qadd'].usage = '~qadd [category]=[content]'; - return { 'name': 'quotes', 'ignorable': true, diff --git a/modules/quotes/usage.json b/modules/quotes/usage.json new file mode 100644 index 0000000..4bd9dbc --- /dev/null +++ b/modules/quotes/usage.json @@ -0,0 +1,7 @@ +{ + '~q': '~q [category]', + '~qsearch': '~qsearch [category]=[search]', + '~rm': '~rm [category]=[quote to delete]', + '~rmlast': '~rmlast [category], + '~qadd': '~qadd [category]=[content]' +} diff --git a/modules/report/report.js b/modules/report/report.js index f3f4c2f..1e6f03d 100644 --- a/modules/report/report.js +++ b/modules/report/report.js @@ -38,7 +38,6 @@ var report = function(dbot) { }; commands['~report'].regex = [/^~report ([^ ]+) ([^ ]+) (.+)$/, 4]; - commands['~report'].usage = '~report [#channel] [username] [reason for reporting]'; return { 'name': 'report', diff --git a/modules/report/usage.json b/modules/report/usage.json new file mode 100644 index 0000000..153ca23 --- /dev/null +++ b/modules/report/usage.json @@ -0,0 +1,3 @@ +{ + '~report': '~report [#channel] [username] [reason for reporting]' +} From cae8a1fc7d19e8b06c1942369a42ac6248e9a15f Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 20:06:29 +0000 Subject: [PATCH 13/27] loaded strings and usage from the modules themselves in reloadModules. some other smaller changes. fixed the syntax of the usage json. careful though this dbot init may delete your database. --- modules/js/usage.json | 4 +-- modules/poll/usage.json | 10 +++--- modules/quotes/usage.json | 10 +++--- modules/report/usage.json | 2 +- run.js | 72 ++++++++++++++++++++++++++++++++------- 5 files changed, 73 insertions(+), 25 deletions(-) diff --git a/modules/js/usage.json b/modules/js/usage.json index a6deb48..09e0c27 100644 --- a/modules/js/usage.json +++ b/modules/js/usage.json @@ -1,4 +1,4 @@ { - '~js': '~js [command]', - '~ajs': '~ajs [command]' + "~js": "~js [command]", + "~ajs": '~ajs [command]" } diff --git a/modules/poll/usage.json b/modules/poll/usage.json index 3fe17f5..1be3414 100644 --- a/modules/poll/usage.json +++ b/modules/poll/usage.json @@ -1,7 +1,7 @@ { - '~newpoll': '~newpoll [pollname] options=[each,poll,option] [Poll Description]', - '~addoption': '~addoption [pollname] [newoption]', - '~rmoption': '~rmoption [pollname] [optiontoremove]', - '~vote': '~vote [pollname] [option]', - '~pdesc': '~pdesc [pollname]' + "~newpoll": "~newpoll [pollname] options=[each,poll,option] [Poll Description]", + "~addoption": "~addoption [pollname] [newoption]", + "~rmoption": "~rmoption [pollname] [optiontoremove]", + "~vote": "~vote [pollname] [option]", + "~pdesc": "~pdesc [pollname]" } diff --git a/modules/quotes/usage.json b/modules/quotes/usage.json index 4bd9dbc..083c727 100644 --- a/modules/quotes/usage.json +++ b/modules/quotes/usage.json @@ -1,7 +1,7 @@ { - '~q': '~q [category]', - '~qsearch': '~qsearch [category]=[search]', - '~rm': '~rm [category]=[quote to delete]', - '~rmlast': '~rmlast [category], - '~qadd': '~qadd [category]=[content]' + "~q": "~q [category]", + "~qsearch": "~qsearch [category]=[search]", + "~rm": "~rm [category]=[quote to delete]", + "~rmlast": "~rmlast [category]", + "~qadd": "~qadd [category]=[content]" } diff --git a/modules/report/usage.json b/modules/report/usage.json index 153ca23..f0003eb 100644 --- a/modules/report/usage.json +++ b/modules/report/usage.json @@ -1,3 +1,3 @@ { - '~report': '~report [#channel] [username] [reason for reporting]' + "~report": "~report [#channel] [username] [reason for reporting]" } diff --git a/run.js b/run.js index fca7978..80b65e1 100644 --- a/run.js +++ b/run.js @@ -10,11 +10,17 @@ var DBot = function(timers) { var rawDB; try { var rawDB = fs.readFileSync('db.json', 'utf-8'); - } catch (e) { + } catch(err) { this.db = {}; // If no db file, make empty one } - if(!this.db) { // If it wasn't empty - this.db = JSON.parse(rawDB); + + try { + if(!this.db) { // If it wasn't empty + this.db = JSON.parse(rawDB); + } + } catch(err) { + console.log('Probably a syntax error in db.json: ' + err); + this.db = {}; } // Repair any deficiencies in the DB; if this is a new DB, that's everything @@ -47,9 +53,15 @@ var DBot = function(timers) { } // Load Strings file - this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); + try { + this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); + } catch(err) { + console.log('Probably a syntax error: ' + err); + this.strings = {}; + } // Initialise run-time resources + this.usage = {}; this.sessionData = {}; this.timers = timers.create(); @@ -101,12 +113,19 @@ DBot.prototype.say = function(server, channel, message) { // 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"; - } + var formattedString; + if(this.strings.hasOwnProperty(string)) { + var lang = this.language; + if(!this.strings[string].hasOwnProperty(lang)) { + lang = "english"; + } - return this.strings[string][lang].format(formatData); + formattedString = this.strings[string][lang].format(formatData); + } else { + formattedString = 'String not found. Something has gone screwy. Maybe.'; + } + + return formattedString; }; /*DBot.prototype.act = function(channel, data) { @@ -132,6 +151,8 @@ DBot.prototype.reloadModules = function() { this.modules = []; this.commands = {}; this.commandMap = {}; // Map of which commands belong to which modules + this.strings = {}; + this.usage = {}; this.timers.clearTimers(); this.save(); @@ -149,11 +170,13 @@ DBot.prototype.reloadModules = function() { this.instance.removeListeners(); this.moduleNames.each(function(name) { - var cacheKey = require.resolve('./modules/' + name); + var moduleDir = './modules/' + name + '/'; + var cacheKey = require.resolve(moduleDir + name); delete require.cache[cacheKey]; try { - var rawModule = require('./modules/' + name); + // Load the module itself + var rawModule = require(moduleDir + name); var module = rawModule.fetch(this); this.rawModules.push(rawModule); @@ -165,6 +188,7 @@ DBot.prototype.reloadModules = function() { module.onLoad(); } + // Load module commands if(module.commands) { var newCommands = module.commands; for(key in newCommands) { @@ -175,10 +199,34 @@ DBot.prototype.reloadModules = function() { } } + // Load the module usage data + var usage = JSON.parse(fs.readFileSync(moduleDir + 'usage.json', 'utf-8')); + for(key in usage) { + if(usage.hasOwnProperty(key)) { + if(this.usage.hasOwnProperty(key)) { + console.log('Usage key clash for ' + key + ' in ' + name); + } else { + this.usage[key] = usage[key]; + } + } + } + + // Load the module string data + var strings = JSON.parse(fs.readFileSync(moduleDir + 'strings.json', 'utf-8')); + for(key in strings) { + if(strings.hasOwnProperty(key)) { + if(this.strings.hasOwnProperty(key)) { + console.log('Strings key clash for ' + key + ' in ' + name); + } else { + this.strings[key] = strings[key]; + } + } + } + this.modules.push(module); } catch(err) { console.log(this.t('module_load_error', {'moduleName': name})); - console.log(err); + console.log('MODULE ERROR: ' + name + ' ' + err); } }.bind(this)); }; From fbf4242d6665e59b249c503be3a32c6a65fdb8de Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 20:08:19 +0000 Subject: [PATCH 14/27] fix js/usage which I already fixed for some reason --- modules/js/usage.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/js/usage.json b/modules/js/usage.json index 09e0c27..6e5b47e 100644 --- a/modules/js/usage.json +++ b/modules/js/usage.json @@ -1,4 +1,4 @@ { "~js": "~js [command]", - "~ajs": '~ajs [command]" + "~ajs": "~ajs [command]" } From 1f2c7fa8357fb32d803f18725d0d536ac2aaa3db Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 20:23:31 +0000 Subject: [PATCH 15/27] added try/catch for no usage/string info, moved module load error back to default stringspace --- modules/admin/strings.json | 6 ------ run.js | 36 ++++++++++++++++++++++-------------- strings.json | 6 ++++++ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/modules/admin/strings.json b/modules/admin/strings.json index 553a096..8ecacd0 100644 --- a/modules/admin/strings.json +++ b/modules/admin/strings.json @@ -64,11 +64,5 @@ "spanish": "Cerrado la categoría: {category}", "na'vi": "{category}ìri oel 'upxareti fmoli", "welsh": "Categori wedi cloi: {category}" - }, - "module_load_error": { - "english": "Failed to load module: {moduleName}", - "spanish": "No se pudó cargar el módulo: {moduleName}", - "na'vi": "Oeru Oel {moduleName}it sung.", - "welsh": "Wedi methu a llwytho modiwl: {moduleName}" } } diff --git a/run.js b/run.js index 80b65e1..129518a 100644 --- a/run.js +++ b/run.js @@ -200,27 +200,35 @@ DBot.prototype.reloadModules = function() { } // Load the module usage data - var usage = JSON.parse(fs.readFileSync(moduleDir + 'usage.json', 'utf-8')); - for(key in usage) { - if(usage.hasOwnProperty(key)) { - if(this.usage.hasOwnProperty(key)) { - console.log('Usage key clash for ' + key + ' in ' + name); - } else { - this.usage[key] = usage[key]; + try { + var usage = JSON.parse(fs.readFileSync(moduleDir + 'usage.json', 'utf-8')); + for(key in usage) { + if(usage.hasOwnProperty(key)) { + if(this.usage.hasOwnProperty(key)) { + console.log('Usage key clash for ' + key + ' in ' + name); + } else { + this.usage[key] = usage[key]; + } } } + } catch(err) { + // Invalid or no usage info } // Load the module string data - var strings = JSON.parse(fs.readFileSync(moduleDir + 'strings.json', 'utf-8')); - for(key in strings) { - if(strings.hasOwnProperty(key)) { - if(this.strings.hasOwnProperty(key)) { - console.log('Strings key clash for ' + key + ' in ' + name); - } else { - this.strings[key] = strings[key]; + try { + var strings = JSON.parse(fs.readFileSync(moduleDir + 'strings.json', 'utf-8')); + for(key in strings) { + if(strings.hasOwnProperty(key)) { + if(this.strings.hasOwnProperty(key)) { + console.log('Strings key clash for ' + key + ' in ' + name); + } else { + this.strings[key] = strings[key]; + } } } + } catch(err) { + // Invalid or no string info } this.modules.push(module); diff --git a/strings.json b/strings.json index f7eb20c..630e213 100644 --- a/strings.json +++ b/strings.json @@ -5,6 +5,12 @@ "na'vi": "Srake sweylu nga pamrel sivi: ", "welsh": "A oeddech chi'n feddwl: " }, + "module_load_error": { + "english": "Failed to load module: {moduleName}", + "spanish": "No se pudó cargar el módulo: {moduleName}", + "na'vi": "Oeru Oel {moduleName}it sung.", + "welsh": "Wedi methu a llwytho modiwl: {moduleName}" + }, "url": { "english": "http://{host}:{port}/{path}" } From f72e29398fd49622139e195717e1e78e5e3383f1 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 20:27:18 +0000 Subject: [PATCH 16/27] fixed module unloading --- modules/admin/admin.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/admin/admin.js b/modules/admin/admin.js index 173e270..99e8a2e 100644 --- a/modules/admin/admin.js +++ b/modules/admin/admin.js @@ -80,7 +80,8 @@ var admin = function(dbot) { 'unload': function(event) { var moduleName = event.params[1]; if(dbot.moduleNames.include(moduleName)) { - var cacheKey = require.resolve('../modules/' + moduleName); + var moduleDir = '../' + moduleName + '/'; + var cacheKey = require.resolve(moduleDir + moduleName); delete require.cache[cacheKey]; var moduleIndex = dbot.moduleNames.indexOf(moduleName); From b641dcd34a5c37d639989d19ff4106385d73ab8b Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 20:31:11 +0000 Subject: [PATCH 17/27] usage info in command --- modules/command/command.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/command/command.js b/modules/command/command.js index ea3043d..6342da2 100644 --- a/modules/command/command.js +++ b/modules/command/command.js @@ -56,10 +56,9 @@ var command = function(dbot) { 'commands': { '~usage': function(event) { var commandName = event.params[1]; - console.log(commandName); - if(dbot.commands.hasOwnProperty(commandName)) { + if(dbot.usage.hasOwnProperty(commandName)) { event.reply('Usage for ' + commandName + ': ' + - dbot.commands[commandName].usage); + dbot.usage[commandName]); } else { event.reply('No usage information for ' + commandName); } @@ -84,8 +83,8 @@ var command = function(dbot) { dbot.save(); } else { if(commandName !== '~') { - if(dbot.commands[commandName].hasOwnProperty('usage')){ - event.reply('Usage: ' + dbot.commands[commandName].usage); + if(dbot.usage.hasOwnProperty(commandName)){ + event.reply('Usage: ' + dbot.usage[commandName]); } else { event.reply(dbot.t('syntax_error')); } From 19c3497f112a056e76aa6e4bc1b984b2755bf86c Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 20:47:50 +0000 Subject: [PATCH 18/27] reload default strings in updateModules --- modules/admin/admin.js | 1 - run.js | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/admin/admin.js b/modules/admin/admin.js index 99e8a2e..d6fae5e 100644 --- a/modules/admin/admin.js +++ b/modules/admin/admin.js @@ -53,7 +53,6 @@ var admin = function(dbot) { // Reload DB, translations and modules. 'reload': function(event) { dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); - dbot.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); dbot.reloadModules(); event.reply(dbot.t('reload')); }, diff --git a/run.js b/run.js index 129518a..e1b5f6e 100644 --- a/run.js +++ b/run.js @@ -151,11 +151,16 @@ DBot.prototype.reloadModules = function() { this.modules = []; this.commands = {}; this.commandMap = {}; // Map of which commands belong to which modules - this.strings = {}; this.usage = {}; this.timers.clearTimers(); this.save(); + try { + this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); + } catch(err) { + this.strings = {}; + } + // Enforce having command. it can still be reloaded, but dbot _will not_ // function without it, so not having it should be impossible if(!this.moduleNames.include("command")) { From 65414f6975f9401e6a85ebf046e5259d13cadb8b Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 21:01:37 +0000 Subject: [PATCH 19/27] OH THE SHAME. THE SHAME OF IT ALL. --- modules/quotes/quotes.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index 582f4e8..772930e 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -156,7 +156,9 @@ var quotes = function(dbot) { } else { // Give total quote count var totalQuoteCount = 0; for(var category in quotes) { - totalQuoteCount += category.length; + if(quotes.hasOwnProperty(category)) { + totalQuoteCount += quotes[category].length; + } } event.reply(dbot.t('total_quotes', {'count': totalQuoteCount})); } @@ -190,7 +192,7 @@ var quotes = function(dbot) { 'url': dbot.t('url', {'host': dbot.webHost, 'port': dbot.webPort, 'path': 'quotes/' + key})})); } else { - event.reply(dbot.t('category_not_found')); + event.reply(dbot.t('category_not_found', {'category': key})); } }, }; From c64e66da1759af7c4de50090824b63ec00b23b7c Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Wed, 12 Dec 2012 18:07:08 +0000 Subject: [PATCH 20/27] Module specific config. Allows specify dbKeys to ensure default objects there for use. --- .gitignore | 2 +- modules/admin/config.json | 3 +++ modules/kick/config.json | 3 +++ modules/quotes/config.json | 3 +++ modules/web/config.json | 4 ++++ run.js | 42 ++++++++++++-------------------------- 6 files changed, 27 insertions(+), 30 deletions(-) create mode 100644 modules/admin/config.json create mode 100644 modules/kick/config.json create mode 100644 modules/quotes/config.json create mode 100644 modules/web/config.json diff --git a/.gitignore b/.gitignore index 1a7610d..a49c313 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # Ignore the user config files -config.json +./config.json # Ignore the user database db.json diff --git a/modules/admin/config.json b/modules/admin/config.json new file mode 100644 index 0000000..e1a07bb --- /dev/null +++ b/modules/admin/config.json @@ -0,0 +1,3 @@ +{ + "dbKeys": [ "bans", "locks" ] +} diff --git a/modules/kick/config.json b/modules/kick/config.json new file mode 100644 index 0000000..10e1e76 --- /dev/null +++ b/modules/kick/config.json @@ -0,0 +1,3 @@ +{ + "dbKeys": [ "kicks", "kickers" ] +} diff --git a/modules/quotes/config.json b/modules/quotes/config.json new file mode 100644 index 0000000..32c3324 --- /dev/null +++ b/modules/quotes/config.json @@ -0,0 +1,3 @@ +{ + "dbKeys": [ "quoteArrs" ] +} diff --git a/modules/web/config.json b/modules/web/config.json new file mode 100644 index 0000000..981e0f7 --- /dev/null +++ b/modules/web/config.json @@ -0,0 +1,4 @@ +{ + "webHost": "localhost", + "webPort": 8080 +} diff --git a/run.js b/run.js index e1b5f6e..661e3d7 100644 --- a/run.js +++ b/run.js @@ -23,35 +23,6 @@ var DBot = function(timers) { this.db = {}; } - // Repair any deficiencies in the DB; if this is a new DB, that's everything - if(!this.db.hasOwnProperty("bans")) { - this.db.bans = {}; - } - if(!this.db.bans.hasOwnProperty("*")) { - this.db.bans["*"] = []; - } - if(!this.db.hasOwnProperty("quoteArrs")) { - this.db.quoteArrs = {}; - } - if(!this.db.hasOwnProperty("kicks")) { - this.db.kicks = {}; - } - if(!this.db.hasOwnProperty("kickers")) { - this.db.kickers = {}; - } - if(!this.db.hasOwnProperty("modehate")) { - this.db.modehate = []; - } - if(!this.db.hasOwnProperty("locks")) { - this.db.locks = []; - } - if(!this.db.hasOwnProperty("ignores")) { - this.db.ignores = {}; - } - if(!this.db.hasOwnProperty('polls')) { - this.db.polls = {}; - } - // Load Strings file try { this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); @@ -236,6 +207,19 @@ DBot.prototype.reloadModules = function() { // Invalid or no string info } + // Load the module config data + try { + var config = JSON.parse(fs.readFileSync(moduleDir + 'config.json', 'utf-8')) + this.config[name] = config; + for(var i=0;i Date: Wed, 12 Dec 2012 18:25:07 +0000 Subject: [PATCH 21/27] Config defaults and file loading changes * Attempts to load config from default file upon failing to load config.json * Stops if db fails to load * Automatically loads config keys into dbot object --- config.json.sample | 4 +++- run.js | 43 +++++++++++++++++++------------------------ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/config.json.sample b/config.json.sample index d665e9c..a7232d0 100644 --- a/config.json.sample +++ b/config.json.sample @@ -13,5 +13,7 @@ ] } }, - "admin": [ "batman" ] + "admin": [ "batman" ], + "moduleNames": [ "ignore", "admin", "command", "dice", "js", "kick", "puns", "quotes", "spelling", "youare" ], + "language": "english" } diff --git a/run.js b/run.js index 661e3d7..69dc469 100644 --- a/run.js +++ b/run.js @@ -5,8 +5,18 @@ require('./snippets'); var DBot = function(timers) { // Load external files - this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); - this.db = null; + try { + this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); + } catch(err) { + console.log('Config file is screwed up. Attempting to load defaults.'); + try { + this.config = JSON.parse(fs.readFileSync('config.json.sample', 'utf-8')); + } catch(err) { + console.log('Error loading sample config. Bugger off. Stopping.'); + process.exit(); + } + } + var rawDB; try { var rawDB = fs.readFileSync('db.json', 'utf-8'); @@ -19,15 +29,15 @@ var DBot = function(timers) { this.db = JSON.parse(rawDB); } } catch(err) { - console.log('Probably a syntax error in db.json: ' + err); - this.db = {}; + console.log('Syntax error in db.json. Stopping: ' + err); + process.exit(); } // Load Strings file try { this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); } catch(err) { - console.log('Probably a syntax error: ' + err); + console.log('Probably a syntax error in strings.json: ' + err); this.strings = {}; } @@ -37,26 +47,11 @@ var DBot = function(timers) { this.timers = timers.create(); // Populate bot properties with config data - this.name = this.config.name || 'dbox'; - this.admin = this.config.admin || [ 'reality' ]; - this.moduleNames = this.config.modules || [ 'ignore', 'admin', 'command', 'dice', 'js', 'kick', 'puns', 'quotes', 'spelling', 'youare' ]; - this.language = this.config.language || 'english'; - this.webHost = this.config.webHost || 'localhost'; - this.webPort = this.config.webPort || 80; - - // It's the user's responsibility to fill this data structure up properly in - // the config file. They can d-d-d-deal with it if they have problems. - this.servers = this.config.servers || { - 'freenode': { - 'server': 'irc.freenode.net', - 'port': 6667, - 'nickserv': 'nickserv', - 'password': 'lolturtles', - 'channels': [ - '#realitest' - ] + for(var configKey in this.config) { + if(this.config.hasOwnProperty(configKey) && this.hasOwnProperty(configKey) === false) { + this[configKey] = this.config[configKey]; } - }; + } // Create JSBot and connect to each server this.instance = jsbot.createJSBot(this.name); From 918a3c4540c2f7c8d4f4237336b0e962e8d5c5cb Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Wed, 12 Dec 2012 18:33:29 +0000 Subject: [PATCH 22/27] Check for required keys in config --- run.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/run.js b/run.js index 69dc469..5a0abce 100644 --- a/run.js +++ b/run.js @@ -5,6 +5,7 @@ require('./snippets'); var DBot = function(timers) { // Load external files + var requiredConfigKeys = [ 'name', 'servers', 'admin', 'moduleNames', 'language' ]; try { this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); } catch(err) { @@ -16,6 +17,13 @@ var DBot = function(timers) { process.exit(); } } + requiredConfigKeys.each(function(key) { + if(!this.config.hasOwnProperty(key)) { + console.log('Error: Please set a value for ' + key + ' in ' + + 'config.json. Stopping.'); + process.exit(); + } + }.bind(this)); var rawDB; try { From 96312303f0e8f14fbbf3cc995707d1e06a371762 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Wed, 12 Dec 2012 18:36:12 +0000 Subject: [PATCH 23/27] web config data now taken from dbot web config --- config.json.sample | 2 -- modules/poll/poll.js | 6 ++++-- modules/quotes/quotes.js | 4 ++-- modules/web/web.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config.json.sample b/config.json.sample index a7232d0..bda53b7 100644 --- a/config.json.sample +++ b/config.json.sample @@ -1,7 +1,5 @@ { "name": "testressionbot", - "webHost": "lolcathost", - "webPort": 80, "servers": { "freenode": { "server": "irc.freenode.net", diff --git a/modules/poll/poll.js b/modules/poll/poll.js index a2a6223..8c79a02 100644 --- a/modules/poll/poll.js +++ b/modules/poll/poll.js @@ -40,7 +40,8 @@ var poll = function(dbot) { } event.reply(dbot.t('poll_created', {'name': name, 'description': description, - 'url': dbot.t('url', {'host': dbot.webHost, 'port': dbot.webPort, 'path': 'polls/' + name})})); + 'url': dbot.t('url', {'host': dbot.config.web.webHost, + 'port': dbot.config.web.webPort, 'path': 'polls/' + name})})); } } }, @@ -141,7 +142,8 @@ var poll = function(dbot) { var name = event.input[1]; if(polls.hasOwnProperty(name)) { event.reply(dbot.t('poll_describe', {'name': name, 'description': polls[name].description, - 'url': dbot.t('url', {'host': dbot.webHost, 'port': dbot.webPort, 'path': 'polls/' + name})})); + 'url': dbot.t('url', {'host': dbot.config.web.webHost, 'port': + dbot.config.web.webPort, 'path': 'polls/' + name})})); } else { event.reply(dbot.t('poll_unexistent', {'name': name})); } diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index 772930e..49a7b71 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -189,8 +189,8 @@ var quotes = function(dbot) { var key = event.params[1].trim().toLowerCase(); if(quotes.hasOwnProperty(key)) { event.reply(dbot.t('quote_link', {'category': key, - 'url': dbot.t('url', {'host': dbot.webHost, - 'port': dbot.webPort, 'path': 'quotes/' + key})})); + 'url': dbot.t('url', {'host': dbot.config.web.webHost, + 'port': dbot.config.web.webPort, 'path': 'quotes/' + key})})); } else { event.reply(dbot.t('category_not_found', {'category': key})); } diff --git a/modules/web/web.js b/modules/web/web.js index 1be542a..af18b31 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -113,7 +113,7 @@ var webInterface = function(dbot) { } }); - app.listen(dbot.webPort); + app.listen(dbot.config.web.webPort); return { 'name': 'web', From d0c47d18eb3137625863c1fd239b88352f2d1142 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Mon, 17 Dec 2012 17:18:31 +0000 Subject: [PATCH 24/27] Moved all data loaded from config to be used only from dbot.config. Changed admin key in to admins to avoid clash with admin module config. Admins should probably be a key under dbot.admin module anyway. --- config.json.sample | 2 +- modules/admin/admin.js | 11 ++++++----- modules/js/js.js | 2 +- modules/kick/kick.js | 6 +++--- modules/puns/puns.js | 2 +- modules/quotes/quotes.js | 6 +++--- modules/web/web.js | 28 ++++++++++++++-------------- run.js | 31 ++++++++++++++----------------- 8 files changed, 43 insertions(+), 45 deletions(-) diff --git a/config.json.sample b/config.json.sample index bda53b7..31c11f6 100644 --- a/config.json.sample +++ b/config.json.sample @@ -11,7 +11,7 @@ ] } }, - "admin": [ "batman" ], + "admins": [ "batman" ], "moduleNames": [ "ignore", "admin", "command", "dice", "js", "kick", "puns", "quotes", "spelling", "youare" ], "language": "english" } diff --git a/modules/admin/admin.js b/modules/admin/admin.js index d6fae5e..d51474b 100644 --- a/modules/admin/admin.js +++ b/modules/admin/admin.js @@ -70,21 +70,22 @@ var admin = function(dbot) { // Load new module 'load': function(event) { var moduleName = event.params[1]; - dbot.moduleNames.push(moduleName); + dbot.config.moduleNames.push(moduleName); dbot.reloadModules(); event.reply(dbot.t('load_module', {'moduleName': moduleName})); }, // Unload a loaded module 'unload': function(event) { + var moduleNames = dbot.config.moduleNames; var moduleName = event.params[1]; - if(dbot.moduleNames.include(moduleName)) { + if(moduleNames.include(moduleName)) { var moduleDir = '../' + moduleName + '/'; var cacheKey = require.resolve(moduleDir + moduleName); delete require.cache[cacheKey]; - var moduleIndex = dbot.moduleNames.indexOf(moduleName); - dbot.moduleNames.splice(moduleIndex, 1); + var moduleIndex = moduleNames.indexOf(moduleName); + moduleNames.splice(moduleIndex, 1); dbot.reloadModules(); event.reply(dbot.t('unload_module', {'moduleName': moduleName})); @@ -134,7 +135,7 @@ var admin = function(dbot) { */ 'listener': function(event) { var commandName = event.params[0]; - if(commands.hasOwnProperty(commandName) && dbot.admin.include(event.user)) { + if(commands.hasOwnProperty(commandName) && dbot.config.admins.include(event.user)) { commands[commandName](event); dbot.save(); } diff --git a/modules/js/js.js b/modules/js/js.js index 83e1bf0..76d5f91 100644 --- a/modules/js/js.js +++ b/modules/js/js.js @@ -22,7 +22,7 @@ var js = function(dbot) { // Run JS code un-sandboxed, with access to DBot memory (admin-only). '~ajs': function(event) { - if(dbot.admin.include(event.user) ) { + if(dbot.config.admins.include(event.user) ) { var ret = eval(event.input[1]); if(ret !== undefined) { event.reply(ret); diff --git a/modules/kick/kick.js b/modules/kick/kick.js index 540f9b7..150fb55 100644 --- a/modules/kick/kick.js +++ b/modules/kick/kick.js @@ -46,10 +46,10 @@ var kick = function(dbot) { 'commands': commands, 'listener': function(event) { - if(event.kickee == dbot.name) { + if(event.kickee == dbot.config.name) { dbot.instance.join(event, event.channel); - event.reply(dbot.t('kicked_dbot', {'botname': dbot.name})); - dbot.db.kicks[dbot.name] += 1; + event.reply(dbot.t('kicked_dbot', {'botname': dbot.config.name})); + dbot.db.kicks[dbot.config.name] += 1; } else { if(!dbot.db.kicks.hasOwnProperty(event.kickee)) { dbot.db.kicks[event.kickee] = 1; diff --git a/modules/puns/puns.js b/modules/puns/puns.js index 7144932..187a652 100644 --- a/modules/puns/puns.js +++ b/modules/puns/puns.js @@ -8,7 +8,7 @@ var puns = function(dbot) { 'listener': function(event) { event.user = dbot.cleanNick(event.user); - if(dbot.moduleNames.include('quotes') && + if(dbot.config.moduleNames.include('quotes') && dbot.db.quoteArrs.hasOwnProperty(event.user)) { event.message = '~q ' + event.user; event.action = 'PRIVMSG'; diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index 49a7b71..abcc073 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -94,10 +94,10 @@ var quotes = function(dbot) { }, '~rmlast': function(event) { - if(rmAllowed == true || dbot.admin.include(event.user)) { + if(rmAllowed == true || dbot.config.admins.include(event.user)) { var key = event.input[1].trim().toLowerCase(); if(quotes.hasOwnProperty(key)) { - if(!dbot.db.locks.include(key) || dbot.admin.include(event.user)) { + if(!dbot.db.locks.include(key) || dbot.config.admins.include(event.user)) { var quote = quotes[key].pop(); if(quotes[key].length === 0) { delete quotes[key]; @@ -116,7 +116,7 @@ var quotes = function(dbot) { }, '~rm': function(event) { - if(rmAllowed == true || dbot.admin.include(event.user)) { + if(rmAllowed == true || dbot.config.admins.include(event.user)) { var key = event.input[1].trim().toLowerCase(); var quote = event.input[2]; diff --git a/modules/web/web.js b/modules/web/web.js index af18b31..9f01c8d 100644 --- a/modules/web/web.js +++ b/modules/web/web.js @@ -9,21 +9,21 @@ var webInterface = function(dbot) { app.set('view engine', 'jade'); app.get('/', function(req, res) { - res.render('index', { 'name': dbot.name }); + res.render('index', { 'name': dbot.config.name }); }); app.get('/connections', function(req, res) { var connections = Object.keys(dbot.instance.connections); - res.render('connections', { 'name': dbot.name, 'connections': connections }); + res.render('connections', { 'name': dbot.config.name, 'connections': connections }); }); app.get('/channels/:connection', function(req, res) { var connection = req.params.connection; if(dbot.instance.connections.hasOwnProperty(connection)) { var channels = Object.keys(dbot.instance.connections[connection].channels); - res.render('channels', { 'name': dbot.name, 'connection': connection, 'channels': channels}); + res.render('channels', { 'name': dbot.config.name, 'connection': connection, 'channels': channels}); } else { - res.render('error', { 'name': dbot.name, 'message': 'No such connection.' }); + res.render('error', { 'name': dbot.config.name, 'message': 'No such connection.' }); } }); @@ -35,10 +35,10 @@ var webInterface = function(dbot) { if(connections.hasOwnProperty(connection) && connections[connection].channels.hasOwnProperty(channel)) { var nicks = Object.keys(connections[connection].channels[channel].nicks); - res.render('users', { 'name': dbot.name, 'connection': connection, + res.render('users', { 'name': dbot.config.name, 'connection': connection, 'channel': channel, 'nicks': nicks }); } else { - res.render('error', { 'name': dbot.name, 'message': 'No such connection or channel.' }); + res.render('error', { 'name': dbot.config.name, 'message': 'No such connection or channel.' }); } }); @@ -64,35 +64,35 @@ var webInterface = function(dbot) { var kicked = dbot.db.kickers[req.params.user]; } - res.render('user', { 'name': dbot.name, 'user': req.params.user, + res.render('user', { 'name': dbot.config.name, 'user': req.params.user, 'channel': channel, 'connection': connection, 'cleanUser': user, 'quotecount': quoteCount, 'kicks': kicks, 'kicked': kicked }); }); // Lists the quote categories app.get('/quotes', function(req, res) { - res.render('quotelist', { 'name': dbot.name, 'quotelist': Object.keys(dbot.db.quoteArrs) }); + res.render('quotelist', { 'name': dbot.config.name, 'quotelist': Object.keys(dbot.db.quoteArrs) }); }); // Lists quotes in a category app.get('/quotes/:key', function(req, res) { var key = req.params.key.toLowerCase(); if(dbot.db.quoteArrs.hasOwnProperty(key)) { - res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[key], locals: { 'url_regex': RegExp.prototype.url_regex() } }); + res.render('quotes', { 'name': dbot.config.name, 'quotes': dbot.db.quoteArrs[key], locals: { 'url_regex': RegExp.prototype.url_regex() } }); } else { - res.render('error', { 'name': dbot.name, 'message': 'No quotes under that key.' }); + res.render('error', { 'name': dbot.config.name, 'message': 'No quotes under that key.' }); } }); // Load random quote category page app.get('/rq', function(req, res) { var rCategory = Object.keys(dbot.db.quoteArrs).random(); - res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[rCategory], locals: { 'url_regex': RegExp.prototype.url_regex() } }); + res.render('quotes', { 'name': dbot.config.name, 'quotes': dbot.db.quoteArrs[rCategory], locals: { 'url_regex': RegExp.prototype.url_regex() } }); }); // Lists all of the polls app.get('/polls', function(req, res) { - res.render('polllist', { 'name': dbot.name, 'polllist': Object.keys(dbot.db.polls) }); + res.render('polllist', { 'name': dbot.config.name, 'polllist': Object.keys(dbot.db.polls) }); }); // Shows the results of a poll @@ -107,9 +107,9 @@ var webInterface = function(dbot) { totalVotes += N; } } - res.render('polls', { 'name': dbot.name, 'description': dbot.db.polls[key].description, 'votees': Object.keys(dbot.db.polls[key].votees), 'options': dbot.db.polls[key].votes, locals: { 'totalVotes': totalVotes, 'url_regex': RegExp.prototype.url_regex() } }); + res.render('polls', { 'name': dbot.config.name, 'description': dbot.db.polls[key].description, 'votees': Object.keys(dbot.db.polls[key].votees), 'options': dbot.db.polls[key].votes, locals: { 'totalVotes': totalVotes, 'url_regex': RegExp.prototype.url_regex() } }); } else { - res.render('error', { 'name': dbot.name, 'message': 'No polls under that key.' }); + res.render('error', { 'name': dbot.config.name, 'message': 'No polls under that key.' }); } }); diff --git a/run.js b/run.js index 5a0abce..fec9441 100644 --- a/run.js +++ b/run.js @@ -5,7 +5,7 @@ require('./snippets'); var DBot = function(timers) { // Load external files - var requiredConfigKeys = [ 'name', 'servers', 'admin', 'moduleNames', 'language' ]; + var requiredConfigKeys = [ 'name', 'servers', 'admins', 'moduleNames', 'language' ]; try { this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); } catch(err) { @@ -55,19 +55,14 @@ var DBot = function(timers) { this.timers = timers.create(); // Populate bot properties with config data - for(var configKey in this.config) { - if(this.config.hasOwnProperty(configKey) && this.hasOwnProperty(configKey) === false) { - this[configKey] = this.config[configKey]; - } - } - // Create JSBot and connect to each server - this.instance = jsbot.createJSBot(this.name); - for(var name in this.servers) { - if(this.servers.hasOwnProperty(name)) { - var server = this.servers[name]; - this.instance.addConnection(name, server.server, server.port, this.admin, function(event) { - var server = this.servers[event.server]; + this.instance = jsbot.createJSBot(this.config.name); + for(var name in this.config.servers) { + if(this.config.servers.hasOwnProperty(name)) { + var server = this.config.servers[name]; + this.instance.addConnection(name, server.server, server.port, + this.config.admin, function(event) { + var server = this.config.servers[event.server]; for(var i=0;i Date: Mon, 17 Dec 2012 19:30:50 +0000 Subject: [PATCH 25/27] Fixed run.js Will now create dbKeys --- run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.js b/run.js index fec9441..d3157f4 100644 --- a/run.js +++ b/run.js @@ -211,7 +211,7 @@ DBot.prototype.reloadModules = function() { try { var config = JSON.parse(fs.readFileSync(moduleDir + 'config.json', 'utf-8')) this.config[name] = config; - for(var i=0;i Date: Mon, 17 Dec 2012 19:37:33 +0000 Subject: [PATCH 26/27] Actually save the database Moved this.save() call to end of reloadModules so new keys are actually saved. --- run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.js b/run.js index d3157f4..8a1087d 100644 --- a/run.js +++ b/run.js @@ -122,7 +122,6 @@ DBot.prototype.reloadModules = function() { this.commandMap = {}; // Map of which commands belong to which modules this.usage = {}; this.timers.clearTimers(); - this.save(); try { this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); @@ -226,6 +225,7 @@ DBot.prototype.reloadModules = function() { console.log('MODULE ERROR: ' + name + ' ' + err); } }.bind(this)); + this.save(); }; DBot.prototype.cleanNick = function(key) { From 0dc5c6d91f8317d82c898f403822889543e39184 Mon Sep 17 00:00:00 2001 From: Sam Nicholls Date: Mon, 17 Dec 2012 12:09:39 -0800 Subject: [PATCH 27/27] Ensure ignores dbKey exists Created dbKeys config for ignores module to prevent meltdown. --- modules/ignore/config.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 modules/ignore/config.json diff --git a/modules/ignore/config.json b/modules/ignore/config.json new file mode 100644 index 0000000..7a4c116 --- /dev/null +++ b/modules/ignore/config.json @@ -0,0 +1,3 @@ +{ + "dbKeys": [ "ignores" ] +}