diff --git a/config.json.sample b/config.json.sample index b41f0f7..78dd1cc 100644 --- a/config.json.sample +++ b/config.json.sample @@ -1,8 +1,15 @@ { - "name": "depressionbot", - "password": "fishes", + "name": "testressionbot", + "servers": { + "freenode": { + "server": "irc.freenode.net", + "port": 6667, + "nickserv": "nickserv", + "password": "lolturtles", + "channels": [ + "#realitest" + ] + } + }, "admin": [ "batman" ], - "channels": [ - "#42" - ] } diff --git a/modules/admin.js b/modules/admin.js index 36e3c1e..2a79884 100644 --- a/modules/admin.js +++ b/modules/admin.js @@ -1,147 +1,135 @@ +/** + * 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 adminCommands = function(dbot) { - var dbot = dbot; - +var admin = function(dbot) { var commands = { - 'join': function(data, params) { - dbot.instance.join(params[1]); - dbot.say(data.channel, 'Joined ' + params[1]); + // Join a channel + 'join': function(event) { + var channel = event.params[1]; + dbot.instance.join(event, channel); + event.reply(dbot.t('join', {'channel': channel})); }, - 'opme': function(data, params) { - dbot.instance.send('MODE ' + params[1] + ' +o ', data.user); + // Leave a channel + 'part': function(event) { + var channel = event.params[1]; + event.instance.part(event, channel); + event.reply(dbot.t('part', {'channel': channel})); }, - 'part': function(data, params) { - dbot.instance.part(params[1]); + // Op admin caller in given channel + 'opme': function(event) { + event.channel = event.params[1]; + dbot.instance.mode(event, '+o ' + event.user); }, // Do a git pull and reload - 'greload': function(data, params) { - var child; - - child = exec("git pull", function (error, stdout, stderr) { - console.log(stderr); - dbot.say(data.channel, dbot.t('gpull')); - commands.reload(data, params); + 'greload': function(event) { + var child = exec("git pull", function (error, stdout, stderr) { + event.reply(dbot.t('gpull')); + commands.reload(event); }.bind(this)); }, - 'reload': function(data, params) { + // 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(); - dbot.say(data.channel, dbot.t('reload')); + event.reply(dbot.t('reload')); }, - 'say': function(data, params) { - if (params[1] === "@") { - var c = data.channel; - } else { - var c = params[1]; - } - var m = params.slice(2).join(' '); - dbot.say(c, m); + // 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; + } + var message = event.params.slice(2).join(' '); + dbot.say(event.server, channel, message); }, - 'act': function(data, params) { - if (params[1] === "@") { - var c = data.channel; - } else { - var c = params[1]; - } - var m = params.slice(2).join(' '); - dbot.act(c, m); - }, - - 'load': function(data, params) { - dbot.moduleNames.push(params[1]); + // Load new module + 'load': function(event) { + var moduleName = event.params[1]; + dbot.moduleNames.push(moduleName); dbot.reloadModules(); - dbot.say(data.channel, dbot.t('load_module', {'moduleName': params[1]})); + event.reply(dbot.t('load_module', {'moduleName': moduleName})); }, - 'unload': function(data, params) { - if(dbot.moduleNames.include(params[1])) { - var cacheKey = require.resolve('../modules/' + params[1]); + // 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(params[1]); + var moduleIndex = dbot.moduleNames.indexOf(moduleName); dbot.moduleNames.splice(moduleIndex, 1); - dbot.reloadModules(); - dbot.say(data.channel, dbot.t('unload_module', {'moduleName': params[1]})); + + event.reply(dbot.t('unload_module', {'moduleName': moduleName})); } else { - dbot.say(data.channel, dbot.t('unload_error', {'moduleName': params[1]})); + event.reply(dbot.t('unload_error', {'moduleName': moduleName})); } }, - 'ban': function(data, params) { - if(dbot.db.bans.hasOwnProperty(params[2])) { - dbot.db.bans[params[2]].push(params[1]); - } else { - dbot.db.bans[params[2]] = [ params[1] ]; + // 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.say(data.channel, dbot.t('banned', {'user': params[1], 'command': params[2]})); + dbot.db.bans[command].push(username); + event.reply(dbot.t('banned', {'user': username, 'command': command})); }, - 'unban': function(data, params) { - if(dbot.db.bans.hasOwnProperty(params[2]) && dbot.db.bans[params[2]].include(params[1])) { - dbot.db.bans[params[2]].splice(dbot.db.bans[params[2]].indexOf(params[1]), 1); - dbot.say(data.channel, dbot.t('unbanned', {'user': params[1], 'command': params[2]})); + // 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 { - dbot.say(data.channel, dbot.t('unban_error', {'user': params[1]})); + event.reply(dbot.t('unban_error', {'user': username})); } }, - 'modehate': function(data, params) { - dbot.db.modehate.push(params[1]); - dbot.say(data.channel, dbot.t('modehate', {'user': params[1]})); - }, - - 'unmodehate': function(data, params) { - dbot.db.modehate.splice(dbot.db.modehate.indexOf(params[1]), 1); - dbot.say(data.channel, dbot.t('unmodehate', {'user': params[1]})); - }, - - 'lock': function(data, params) { - dbot.db.locks.push(params[1]); - dbot.say(data.channel, dbot.t('qlock', {'category': params[1]})); + // 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 { - // These commands are implemented as their own listener so it can easily - // check whether the user is the admin, and so that the admin can't ban - // themselves and then not be able to rectify it... - 'listener': function(data) { - if(data.channel == dbot.name) data.channel = data.user; + 'name': 'admin', + 'ignorable': false, - params = data.message.split(' '); - if(commands.hasOwnProperty(params[0]) && dbot.admin.include(data.user)) { - commands[params[0]](data, params); + /** + * 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(); } }, - - 'onLoad': function() { - return { - '~resetadmin': function(data, params) { - dbot.admin = dbot.config.admin; - } - } - }, - - 'on': 'PRIVMSG', - - 'name': 'admin', - - 'ignorable': false + 'on': 'PRIVMSG' }; }; exports.fetch = function(dbot) { - return adminCommands(dbot); + return admin(dbot); }; diff --git a/modules/autoshorten.js b/modules/autoshorten.js index ff4fc90..426941a 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -1,41 +1,38 @@ +/** + * 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) { - var name = 'autoshorten'; - var dbot = dbot; - return { - 'listener': function(data) { - if((dbot.db.ignores.hasOwnProperty(data.user) && - dbot.db.ignores[data.user].include(name)) == false) { - var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; - var urlMatches = data.message.match(urlRegex); + 'name': 'autoshorten', + 'ignorable': true, - 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': 'nc.no.de', - 'port': 80, - 'path': '/mkurl?url=' + escape(url) - }; + 'listener': function(event) { + var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; + var urlMatches = event.message.match(urlRegex); - http.get(options, function(res) { - res.setEncoding('utf8'); - res.on('data', function (response) { - dbot.say(data.channel, dbot.t('shorten_link', {'user': data.user}) + JSON.parse(response).surl); - }); + 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': 'nc.no.de', + 'port': 80, + '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', - - 'name': name, - - 'ignorable': true + 'on': 'PRIVMSG' }; } diff --git a/modules/badwords.js b/modules/badwords.js deleted file mode 100644 index d53dab0..0000000 --- a/modules/badwords.js +++ /dev/null @@ -1,56 +0,0 @@ -// Find which badwords are currently enacted in the current channel -var badwords = function(dbot) { - var name = 'badwords'; - var dbot = dbot; - var badWordLock = false; - - var commands = { - '~badwords': function(data, params) { - if(badWordLock == true) { - dbot.say('reality', 'Another badwords query is in action. Try again in a few seconds.'); - } else { - data.channel = '#42'; - badWordLock = true; - - dbot.sessionData.badwords.waiting = true; - - dbot.say('bots', 'badwords ' + data.channel + ' list'); - dbot.instance.addListener('PRIVMSG', - dbot.sessionData.badwords = {}; - badWordLock = false; - } - } - }; - - return { - 'onLoad': function() { - if(!dbot.sessionData.hasOwnProperty('badwords')) { - dbot.sessionData.badwords = {}; - } - - return commands; - }, - - 'listener': function(data) { - if(data.channel === 'bots') { - if(data.message.indexOf('bad words list is empty') != -1) { - dbot.sessionData.badwords.count = 0; - dbot.sessionData.badwords.finished = true; - } else { - var wordMatch = data.message.valMatch(/\w([1-10])\w(.*)/, 2); - dbot.say('reality', wordMatch[1]); - } - } - }, - - 'on': 'PRIVMSG', - - 'name': name, - - 'ignorable': true - }; -}; - -exports.fetch = function(dbot) { - return badwords(dbot); -}; diff --git a/modules/command.js b/modules/command.js index 1da6b65..5f78d8e 100644 --- a/modules/command.js +++ b/modules/command.js @@ -1,123 +1,83 @@ -// Module which handles the command execution syntax for DBot. Not much is going -// to work without this. +/** + * 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) { - var dbot = 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 { - 'onLoad': function() { - return { - '~ignore': function(data, params) { - var ignorableModules = []; - for(var i=0;i 1) { var total = " (total " + rolls[i][1].sum(); @@ -79,7 +79,7 @@ var dice = function(dbot) { } else { var total = ""; } - dbot.say(data.channel, rolls[i][0] + ": " + rolls[i][1].join(" ") + total); + event.reply(rolls[i][0] + ": " + rolls[i][1].join(" ") + total); } } } diff --git a/modules/drama.js b/modules/drama.js index 27949b5..fc9aa3a 100644 --- a/modules/drama.js +++ b/modules/drama.js @@ -1,3 +1,7 @@ +/** + * Module Name: Drama + * Description: Experimental, you probably don't want it. + */ var brain = require('brain'); var drama = function(dbot) { @@ -25,70 +29,65 @@ var drama = function(dbot) { var bayes = new brain.BayesianClassifier(options); var commands = { - '~train': function(data, params) { - if(dbot.admin.include(data.user)) { - bayes.train(last[params[1]][params[2]], params[3]); - dbot.say(data.channel, 'Last thing ' + params[2] + ' said in ' + - params[1] + ' (' + last[params[1]][params[2]] + ') classified as \'' + params[3] + '\''); + '~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(data, params) { - if(dbot.admin.include(data.user)) { - var category = params[1]; - params.splice(0, 2); - var msg = params.join(' '); + '~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); - dbot.say(data.channel, '\'' + msg + '\' classified as \'' + category + '\''); + event.reply('\'' + msg + '\' classified as \'' + category + '\''); } }, - '~classify': function(data, params) { - params.splice(0, 1); - var msg = params.join(' '); + '~classify': function(event) { + event.params.splice(0, 1); + var msg = event.params.join(' '); bayes.classify(msg, function(category) { - dbot.say(data.channel, 'Classified as: ' + category + '!'); + event.reply('Classified as: ' + category + '!'); }.bind(this)); } } return { - 'onLoad': function() { - return commands; - }, + '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(data.user)) { - dbot.db.drama.beinganasshole[data.user]++; + if(dbot.db.drama.beinganasshole.hasOwnProperty(event.user)) { + dbot.db.drama.beinganasshole[event.user]++; } else { - dbot.db.drama.beinganasshole[data.user] = 1; + dbot.db.drama.beinganasshole[event.user] = 1; } } else if(category === 'sd') { - if(dbot.db.drama.sd.hasOwnProperty(data.user)) { - dbot.db.drama.sd[data.user]++; + if(dbot.db.drama.sd.hasOwnProperty(event.user)) { + dbot.db.drama.sd[event.user]++; } else { - dbot.db.drama.sd[data.user] = 1; + dbot.db.drama.sd[event.user] = 1; } } } }.bind(this)); - if(last.hasOwnProperty(data.channel)) { - last[data.channel][data.user] = data.message; + if(last.hasOwnProperty(event.channel)) { + last[event.channel][event.user] = data.message; } else { - last[data.channel] = { }; - last[data.channel][data.user] = data.message; + last[event.channel] = { }; + last[event.channel][event.user] = data.message; } }, - - 'on': 'PRIVMSG', - - 'name': 'drama', - - 'ignorable': false + 'on': 'PRIVMSG' }; } diff --git a/modules/ignore.js b/modules/ignore.js new file mode 100644 index 0000000..b7330b7 --- /dev/null +++ b/modules/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] = urlMatches[0]; + } + }, + 'on': 'PRIVMSG' + }; +}; + +exports.fetch = function(dbot) { + return link(dbot); +}; diff --git a/modules/modehate.js b/modules/modehate.js deleted file mode 100644 index 4bc25eb..0000000 --- a/modules/modehate.js +++ /dev/null @@ -1,23 +0,0 @@ -var modehate = function(dbot) { - var dbot = dbot; - - return { - 'listener': function(data, params) { - if(data.raw[0].indexOf('-oooo') != -1) { - dbot.instance.send('KICK #42 ' + data.user + ' :gtfo - mass deop protection'); - } else if(dbot.db.modehate.include(data.user) && data.raw[0].indexOf('-o') != -1) { - dbot.instance.send('KICK ' + data.channel + ' ' + data.user + ' :gtfo'); - } - }, - - 'on': 'MODE', - - 'name': 'modehate', - - 'ignorable': false - }; -}; - -exports.fetch = function(dbot) { - return modehate(dbot); -}; diff --git a/modules/poll.js b/modules/poll.js new file mode 100644 index 0000000..cebeed9 --- /dev/null +++ b/modules/poll.js @@ -0,0 +1,85 @@ +var poll = function(dbot) { + if(!dbot.db.hasOwnProperty('polls')) { + dbot.db.polls = {}; + } + var polls = dbot.db.polls; + var commands = { + '~newpoll': function(event) { + var name = event.input[1]; + var options = event.input[2].split(','); + var description = event.input[3]; + + 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 { + polls[name] = { + 'name': name, + 'description': description, + 'owner': event.user, + 'votes': {}, + 'votees': {} + }; + + for(var i=0;i 0) { + altKey = key.replace(/ /g, '_'); + } + + 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 the biggest categories - '~qstats': function(data, params) { + // Shows a list of the biggest categories + '~qstats': function(event) { var qSizes = []; for(var cat in quotes) { if(quotes[cat].length != 0) { @@ -77,76 +73,55 @@ var quotes = function(dbot) { qString += qSizes[i][0] + " (" + qSizes[i][1] + "), "; } - dbot.say(data.channel, qString.slice(0, -2)); + event.reply(qString.slice(0, -2)); }, - '~qsearch': function(data, params) { - if(params[2] === undefined) { - dbot.say(data.channel, dbot.t('syntax_error')); - } else { - params[1].trim(); - key = params[1].toLowerCase(); - if(!quotes.hasOwnProperty(key)) { - dbot.say(data.channel, dbot.t('empty_category')); - } else { - var matches = []; - - quotes[key].each(function(quote) { - if(quote.indexOf(params[2]) != -1) { - matches.push(quote); - } - }.bind(this)); - - if(matches.length == 0) { - dbot.say(data.channel, dbot.t('no_results')); - } else { - dbot.say(data.channel, params[1] + ' (' + params[2] + '): ' + matches.random() + ' [' + matches.length + ' results]'); + // Search a given category for some text. + '~qsearch': function(event) { + var haystack = event.input[1].trim().toLowerCase(); + var needle = event.input[2]; + if(quotes.hasOwnProperty(haystack)) { + var matches = []; + quotes[haystack].each(function(quote) { + if(quote.indexOf(needle) != -1) { + matches.push(quote); } + }.bind(this)); + + if(matches.length == 0) { + event.reply(dbot.t('no_results')); + } else { + event.reply(dbot.t('search_results', {'category': haystack, 'needle': needle, + 'quote': matches.random(), 'matches': matches.length})); } + } else { + event.reply(dbot.t('empty_category')); } }, - '~rmlast': function(data, params) { - if(rmAllowed == true || dbot.admin.include(data.user)) { - var q = data.message.valMatch(/^~rmlast ([\d\w\s-]*)/, 2); - if(q) { - q[1] = q[1].trim() - key = q[1].toLowerCase(); - if(quotes.hasOwnProperty(q[1])) { - if(!dbot.db.locks.include(q[1]) || dbot.admin.include(data.user)) { - var quote = quotes[key].pop(); - if(quotes[key].length === 0) { - delete quotes[key]; - } - rmAllowed = false; - dbot.say(data.channel, '\'' + quote + '\'' + - dbot.t('removed_from') + q[1]); - } else { - dbot.say(data.channel, dbot.t('locked_category', {'category': q[1]})); + '~rmlast': function(event) { + if(rmAllowed == true || dbot.admin.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)) { + var quote = quotes[key].pop(); + if(quotes[key].length === 0) { + delete quotes[key]; } + rmAllowed = false; + event.reply(dbot.t('removed_from', {'quote': quote, 'category': key})); } else { - dbot.say(data.channel, dbot.t('no_quotes', {'category': q[1]})); + event.reply(dbot.t('locked_category', {'category': q[1]})); } } else { - var last = addStack.pop(); - if(last) { - if(!dbot.db.locks.include(last)) { - quotes[last].pop(); - rmAllowed = false; - dbot.say(data.channel, dbot.t('last_removed', {'category': last})); - } else { - dbot.say(data.channel, dbot.t('locked_category', {'category': last})); - } - } else { - dbot.say(data.channel, dbot.t('no_recent_adds')); - } + event.reply(dbot.t('no_quotes', {'category': q[1]})); } } else { - dbot.say(data.channel, dbot.t('rmlast_spam')); + event.reply(dbot.t('rmlast_spam')); } }, - '~rm': function(data, params) { + /*'~rm': function(data, params) { if(rmAllowed == true || dbot.admin.include(data.user)) { var q = data.message.valMatch(/^~rm ([\d\w\s-]*) (.+)$/, 3); if(q) { @@ -175,82 +150,57 @@ var quotes = function(dbot) { } else { dbot.say(data.channel, dbot.t('rmlast_spam')); } - }, + },*/ - '~qcount': function(data, params) { - var q = data.message.valMatch(/^~qcount ([\d\w\s-]*)/, 2); - if(q) { - q[1] = q[1].trim(); - key = q[1].toLowerCase(); + '~qcount': function(event) { + var input = event.message.valMatch(/^~qcount ([\d\w\s-]*)/, 2); + if(input) { // Give quote count for named category + var key = input[1].trim().toLowerCase(); if(quotes.hasOwnProperty(key)) { - dbot.say(data.channel, dbot.t('quote_count', {'category': q[1], 'count': quotes[key].length})); + event.reply(dbot.t('quote_count', {'category': key, 'count': quotes[key].length})); } else { - dbot.say(data.channel, dbot.t('no_quotes', {'category': q[1]})); + event.reply(dbot.t('no_quotes', {'category': key})); } } else { // Give total quote count var totalQuoteCount = 0; for(var category in quotes) { totalQuoteCount += category.length; } - dbot.say(data.channel, dbot.t('total_quotes', {'count': totalQuoteCount})); + event.reply(dbot.t('total_quotes', {'count': totalQuoteCount})); } }, - '~qadd': function(data, params) { - var q = data.message.valMatch(/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3); - if(q) { - key = q[1].toLowerCase(); - if(!Object.isArray(quotes[key])) { - quotes[key] = []; - } else { - if (quotes[key].include(q[2])) { - dbot.say(data.channel, dbot.t('quote_exists')); - return; - } - } - quotes[key].push(q[2]); - addStack.push(q[1]); - rmAllowed = true; - dbot.say(data.channel, dbot.t('quote_saved', {'category': q[1], 'count': quotes[key].length})); + '~qadd': function(event) { + var key = event.input[1].toLowerCase(); + var text = event.input[2]; + if(!Object.isArray(quotes[key])) { + quotes[key] = []; + } + + if(quotes[key].include(text)) { + event.reply(dbot.t('quote_exists')); } else { - dbot.say(data.channel, dbot.t('syntax_error')); + quotes[key].push(text); + rmAllowed = true; + event.reply(dbot.t('quote_saved', {'category': key, 'count': quotes[key].length})); } }, - '~qset': function(data, params) { - var q = data.message.valMatch(/^~qset ([\d\w\s-]*)=(.+)$/, 3); - if(q) { - q[1] = q[1].trim(); - key = q[1].toLowerCase(); - if(!quotes.hasOwnProperty(key) || (quotes.hasOwnProperty(key) && - quotes[key].length == 1)) { - quotes[key] = [q[2]]; - dbot.say(data.channel, dbot.t('quote_saved', {'category': q[1], 'count': 1})); - } else { - dbot.say(data.channel, dbot.t('quote_replace')); - } - } - }, - - '~rq': function(data, params) { + '~rq': function(event) { var rQuote = Object.keys(quotes).random(); - dbot.say(data.channel, rQuote + ': ' + interpolatedQuote(rQuote)); - }, - - '~d': function(data, params) { - dbot.say(data.channel, data.user + ': ' + interpolatedQuote(dbot.name)); + event.reply(rQuote + ': ' + interpolatedQuote(rQuote)); }, - '~link': function(data, params) { - if(params[1] === undefined || !quotes.hasOwnProperty(params[1].toLowerCase())) { - dbot.say(data.channel, dbot.t('syntax_error')); + '~link': function(event) { + var key = event.params[1].trim().toLowerCase(); + if(quotes.hasOwnProperty(key)) { + event.reply(dbot.t('quote_link', {'category': key}) + ' - http://nc.no.de:443/quotes/' + key); } else { - dbot.say(data.channel, dbot.t('quote_link', {'category': params[1]}) + - ' - http://nc.no.de:443/quotes/' + params[1]); + event.reply(dbot.t('category_not_found')); } }, - '~qprune': function(data) { + '~qprune': function(event) { var pruned = [] for(key in quotes) { if(quotes.hasOwnProperty(key)) { @@ -261,22 +211,31 @@ var quotes = function(dbot) { } } if(pruned.length > 0) { - dbot.say(data.channel, dbot.t('prune', {'categories': pruned.join(", ")})); + event.reply(dbot.t('prune', {'categories': pruned.join(", ")})); } else { - dbot.say(data.channel, dbot.t('no_prune')); + 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['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2]; + commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; + return { + 'name': 'quotes', + 'ignorable': true, + 'commands': commands, + 'onLoad': function() { dbot.timers.addTimer(1000 * 60 * 3, function() { rmAllowed = true; }); - return commands; }, - // For automatic quote retrieval + /* For automatic quote retrieval 'listener': function(data, params) { if((dbot.db.ignores.hasOwnProperty(data.user) && dbot.db.ignores[data.user].include(name)) == false) { @@ -304,11 +263,7 @@ var quotes = function(dbot) { } }, - 'on': 'PRIVMSG', - - 'name': name, - - 'ignorable': true + 'on': 'PRIVMSG',*/ }; }; diff --git a/modules/spelling.js b/modules/spelling.js index 37f3d51..28d6006 100644 --- a/modules/spelling.js +++ b/modules/spelling.js @@ -1,10 +1,8 @@ var spelling = function(dbot) { - var name = 'spelling'; - var dbot = dbot; var last = {}; - var correct = function (data, correction, candidate, output_callback) { - var rawCandidates = last[data.channel][candidate].split(' ').allGroupings(); + var correct = function (event, correction, candidate, output_callback) { + var rawCandidates = last[event.channel][candidate].split(' ').allGroupings(); var candidates = []; for(var i=0;i