3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 19:52:36 +01:00

autoshorten

This commit is contained in:
Luke Slater 2012-04-14 06:06:40 +01:00
parent 2b81605e2b
commit 4290126222
2 changed files with 31 additions and 0 deletions

30
modules/autoshorten.js Normal file
View File

@ -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);
};

View File

@ -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;