From 74369c5de649f202e26fddfcb104fd0ce43a0ec3 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Wed, 23 May 2012 19:45:14 +0100 Subject: [PATCH] converted autoshorten and dice to new format --- modules/autoshorten.js | 17 ++++++++++------- modules/dice.js | 18 +++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/modules/autoshorten.js b/modules/autoshorten.js index ff4fc90..9574142 100644 --- a/modules/autoshorten.js +++ b/modules/autoshorten.js @@ -1,3 +1,8 @@ +/** + * 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) { @@ -5,11 +10,11 @@ var autoshorten = function(dbot) { var dbot = dbot; return { - 'listener': function(data) { - if((dbot.db.ignores.hasOwnProperty(data.user) && - dbot.db.ignores[data.user].include(name)) == false) { + 'listener': function(event) { + if((dbot.db.ignores.hasOwnProperty(event.user) && + dbot.db.ignores[event.user].include(name)) == false) { var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; - var urlMatches = data.message.match(urlRegex); + var urlMatches = event.message.match(urlRegex); if(urlMatches !== null && urlMatches[0].length > 80) { var url = urlMatches[0]; // Only doing one, screw you. @@ -24,7 +29,7 @@ var autoshorten = function(dbot) { 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); + event.reply(dbot.t('shorten_link', {'user': event.user}) + JSON.parse(response).surl); }); }); } @@ -32,9 +37,7 @@ var autoshorten = function(dbot) { }, 'on': 'PRIVMSG', - 'name': name, - 'ignorable': true }; } diff --git a/modules/dice.js b/modules/dice.js index 847a257..613b455 100644 --- a/modules/dice.js +++ b/modules/dice.js @@ -42,19 +42,19 @@ var normalizeDiceSpec = function (specString) { var dice = function(dbot) { var commands = { - '~roll': function (data, params) { + '~roll': function (event) { var rolls = []; - if (params.length === 1) { - params.push("d6"); + if (event.params.length === 1) { + event.params.push("d6"); } - for (var i = 1; i < params.length; i++) { - var diceSpec = parseDiceSpec(params[i]); + for (var i = 1; i < event.params.length; i++) { + var diceSpec = parseDiceSpec(event.params[i]); if (diceSpec === false) { - rolls.push([params[i], false]); + rolls.push([event.params[i], false]); } else { - rolls.push([normalizeDiceSpec(params[i]), [], diceSpec["modifier"]]); + 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"])); } @@ -63,7 +63,7 @@ var dice = function(dbot) { for (var i = 0; i < rolls.length; i++) { if (rolls[i][1] === false) { - dbot.say(data.channel, rolls[i][0] + ": invalid dice spec"); + event.reply(rolls[i][0] + ": invalid dice spec"); } else { if (rolls[i][1].length > 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); } } }