mirror of
https://github.com/reality/dbot.git
synced 2025-01-23 10:34:31 +01:00
fixt link [#131]
This commit is contained in:
parent
f532aee4ab
commit
b733564cb2
@ -7,9 +7,9 @@ var request = require('request'),
|
||||
_ = require('underscore')._;
|
||||
|
||||
var link = function(dbot) {
|
||||
var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
||||
var links = {};
|
||||
var fetchTitle = function(event, link) {
|
||||
this.urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
||||
this.links = {};
|
||||
this.fetchTitle = function(event, link) {
|
||||
request(link, function (error, response, body) {
|
||||
if(!error && response.statusCode == 200) {
|
||||
body = body.replace(/(\r\n|\n\r|\n)/gm, " ");
|
||||
@ -23,36 +23,34 @@ var link = function(dbot) {
|
||||
|
||||
var commands = {
|
||||
'~title': function(event) {
|
||||
var link = links[event.channel.name];
|
||||
if(_.isUndefined(event.params[1])) {
|
||||
var urlMatches = event.params[1].match(urlRegex);
|
||||
var link = this.links[event.channel.name];
|
||||
if(!_.isUndefined(event.params[1])) {
|
||||
var urlMatches = event.params[1].match(this.urlRegex);
|
||||
if(urlMatches !== null) {
|
||||
link = urlMatches[0];
|
||||
}
|
||||
}
|
||||
fetchTitle(event, link);
|
||||
this.fetchTitle(event, link);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
'name': 'link',
|
||||
'ignorable': true,
|
||||
'commands': commands,
|
||||
this.name = 'link';
|
||||
this.ignorable = true;
|
||||
this.commands = commands;
|
||||
|
||||
'listener': function(event) {
|
||||
var urlMatches = event.message.match(urlRegex);
|
||||
if(urlMatches !== null) {
|
||||
links[event.channel.name] = urlMatches[0];
|
||||
this.listener = function(event) {
|
||||
var urlMatches = event.message.match(this.urlRegex);
|
||||
if(urlMatches !== null) {
|
||||
this.links[event.channel.name] = urlMatches[0];
|
||||
|
||||
if(dbot.config.link.autoTitle == true) {
|
||||
fetchTitle(event, urlMatches[0]);
|
||||
}
|
||||
if(dbot.config.link.autoTitle == true) {
|
||||
this.fetchTitle(event, urlMatches[0]);
|
||||
}
|
||||
},
|
||||
'on': 'PRIVMSG'
|
||||
};
|
||||
}
|
||||
}.bind(this);
|
||||
this.on = 'PRIVMSG';
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return link(dbot);
|
||||
return new link(dbot);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user