/** * Module Name: Link * Description: Stores recent channel links, with commands to retrieve * information about links. */ var request = require('request'), _ = require('underscore')._, ent = require('ent'); var link = function(dbot) { this.urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; this.links = {}; this.handlers = []; this.api = { 'addHandler': function(name, regex, handler) { this.handlers.push({ 'name': name, 'regex': regex, 'callback': handler }); }, 'getTitle': function(link, callback) { var limit = 1000000, size = 0, page = request(link.replace('https', 'http'), function(error, response, body) { if(!error && response.statusCode == 200) { body = body.replace(/(\r\n|\n\r|\n)/gm, " "); var title = body.valMatch(/