2012-04-14 07:08:54 +02:00
|
|
|
var http = require('http');
|
|
|
|
|
2012-04-14 07:06:40 +02:00
|
|
|
var autoshorten = function(dbot) {
|
2012-04-15 23:04:58 +02:00
|
|
|
var name = 'autoshorten';
|
2012-04-14 07:06:40 +02:00
|
|
|
var dbot = dbot;
|
|
|
|
|
|
|
|
return {
|
|
|
|
'listener': function(data) {
|
2012-04-15 23:04:58 +02:00
|
|
|
if((dbot.db.ignores.hasOwnProperty(data.user) &&
|
|
|
|
dbot.db.ignores[data.user].include(name)) == false) {
|
|
|
|
var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
|
|
|
var urlMatches = data.message.match(urlRegex);
|
|
|
|
|
|
|
|
if(urlMatches !== null && urlMatches[0].length > 65) {
|
|
|
|
var url = urlMatches[0]; // Only doing one, screw you.
|
|
|
|
|
|
|
|
// TODO: Make this use a decent URL shortener. Mine is shit.
|
|
|
|
var options = {
|
|
|
|
'host': 'nc.no.de',
|
|
|
|
'port': 80,
|
|
|
|
'path': '/mkurl?url=' + escape(url)
|
|
|
|
};
|
|
|
|
|
|
|
|
http.get(options, function(res) {
|
|
|
|
res.setEncoding('utf8');
|
|
|
|
res.on('data', function (response) {
|
|
|
|
dbot.say(data.channel, 'Shortened link from ' + data.user + ': ' + JSON.parse(response).surl);
|
|
|
|
});
|
2012-04-14 07:26:48 +02:00
|
|
|
});
|
2012-04-15 23:04:58 +02:00
|
|
|
}
|
2012-04-14 07:06:40 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-15 22:43:02 +02:00
|
|
|
'on': 'PRIVMSG',
|
|
|
|
|
2012-04-15 23:04:58 +02:00
|
|
|
'name': name,
|
2012-04-15 22:43:02 +02:00
|
|
|
|
|
|
|
'ignorable': true
|
2012-04-14 07:06:40 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return autoshorten(dbot);
|
|
|
|
};
|