diff --git a/modules/autoshorten.js b/modules/autoshorten.js new file mode 100644 index 0000000..7ccdb6d --- /dev/null +++ b/modules/autoshorten.js @@ -0,0 +1,30 @@ +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); +}; diff --git a/modules/command.js b/modules/command.js index 6f7f289..f7f5147 100644 --- a/modules/command.js +++ b/modules/command.js @@ -33,6 +33,7 @@ var command = function(dbot) { '~ignore': ignoreCommands }; }, + 'listener': function(data) { var params = data.message.split(' '); if(data.channel == dbot.name) data.channel = data.user;