3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 20:22:39 +01:00

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 http = require('http');
var autoshorten = function(dbot) { var autoshorten = function(dbot) {
@ -5,11 +10,11 @@ var autoshorten = function(dbot) {
var dbot = dbot; var dbot = dbot;
return { return {
'listener': function(data) { 'listener': function(event) {
if((dbot.db.ignores.hasOwnProperty(data.user) && if((dbot.db.ignores.hasOwnProperty(event.user) &&
dbot.db.ignores[data.user].include(name)) == false) { dbot.db.ignores[event.user].include(name)) == false) {
var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; 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) { if(urlMatches !== null && urlMatches[0].length > 80) {
var url = urlMatches[0]; // Only doing one, screw you. var url = urlMatches[0]; // Only doing one, screw you.
@ -24,7 +29,7 @@ var autoshorten = function(dbot) {
http.get(options, function(res) { http.get(options, function(res) {
res.setEncoding('utf8'); res.setEncoding('utf8');
res.on('data', function (response) { 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', 'on': 'PRIVMSG',
'name': name, 'name': name,
'ignorable': true 'ignorable': true
}; };
} }

View File

@ -42,19 +42,19 @@ var normalizeDiceSpec = function (specString) {
var dice = function(dbot) { var dice = function(dbot) {
var commands = { var commands = {
'~roll': function (data, params) { '~roll': function (event) {
var rolls = []; var rolls = [];
if (params.length === 1) { if (event.params.length === 1) {
params.push("d6"); event.params.push("d6");
} }
for (var i = 1; i < params.length; i++) { for (var i = 1; i < event.params.length; i++) {
var diceSpec = parseDiceSpec(params[i]); var diceSpec = parseDiceSpec(event.params[i]);
if (diceSpec === false) { if (diceSpec === false) {
rolls.push([params[i], false]); rolls.push([event.params[i], false]);
} else { } else {
rolls.push([normalizeDiceSpec(params[i]), [], diceSpec["modifier"]]); rolls.push([normalizeDiceSpec(event.params[i]), [], diceSpec["modifier"]]);
for (var j = 0; j < diceSpec["count"] ; j++) { for (var j = 0; j < diceSpec["count"] ; j++) {
rolls[rolls.length-1][1].push(Math.ceil(Math.random() * diceSpec["sides"])); 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++) { for (var i = 0; i < rolls.length; i++) {
if (rolls[i][1] === false) { if (rolls[i][1] === false) {
dbot.say(data.channel, rolls[i][0] + ": invalid dice spec"); event.reply(rolls[i][0] + ": invalid dice spec");
} else { } else {
if (rolls[i][1].length > 1) { if (rolls[i][1].length > 1) {
var total = " (total " + rolls[i][1].sum(); var total = " (total " + rolls[i][1].sum();
@ -79,7 +79,7 @@ var dice = function(dbot) {
} else { } else {
var total = ""; var total = "";
} }
dbot.say(data.channel, rolls[i][0] + ": " + rolls[i][1].join(" ") + total); event.reply(rolls[i][0] + ": " + rolls[i][1].join(" ") + total);
} }
} }
} }