mirror of
https://github.com/reality/dbot.git
synced 2024-12-24 19:52:36 +01:00
autoshorten
This commit is contained in:
parent
2b81605e2b
commit
4290126222
30
modules/autoshorten.js
Normal file
30
modules/autoshorten.js
Normal 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);
|
||||
};
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user