converted autoshorten and dice to new format

This commit is contained in:
Luke Slater 2012-05-23 19:45:14 +01:00
parent 9a9f9a662b
commit 74369c5de6
2 changed files with 19 additions and 16 deletions

View File

@ -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
};
}

View File

@ -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);
}
}
}