3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-01 00:19:29 +01:00
dbot/modules/autoshorten.js

33 lines
913 B
JavaScript
Raw Normal View History

2012-04-14 07:08:54 +02:00
var http = require('http');
2012-04-14 07:06:40 +02:00
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.
2012-04-14 07:21:38 +02:00
var options = {
'host': 'nc.no.de',
'port': 80,
'path': '/mkurl?url=' + escape(url)
};
http.get(options, function(response) {
2012-04-14 07:06:40 +02:00
dbot.say(data.channel, 'Shortened link from ' + data.user + ': ' + response.surl);
});
}
},
'on': 'PRIVMSG'
};
}
exports.fetch = function(dbot) {
return autoshorten(dbot);
};