3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-24 04:49:25 +01:00
dbot/modules/autoshorten.js
2012-04-14 06:08:54 +01:00

33 lines
948 B
JavaScript

var http = require('http');
var autoshorten = function(dbot) {
var dbot = dbot;
return {
'listener': function(data) {
var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var urlMatches = data.message.match(urlRegex);
if(urlMatches !== null) {
var url = urlMatches[0]; // Only doing one, screw you.
var site = http.createClient(80, 'http://nc.no.de');
var request = site.request("GET", 'mkurl', { 'host' : 'http://nc.no.de/',
'url': url});
request.end();
request.on('response', function(response) {
dbot.say(data.channel, 'Shortened link from ' + data.user + ': ' + response.surl);
});
}
},
'on': 'PRIVMSG'
};
}
exports.fetch = function(dbot) {
return autoshorten(dbot);
};