diff --git a/modules/link/link.js b/modules/link/link.js index e07c178..94a2287 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -11,7 +11,9 @@ var link = function(dbot) { 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) { + var limit = 25 * 1000, + size = 0, + page = request(link, function(error, response, body) { if(!error && response.statusCode == 200) { body = body.replace(/(\r\n|\n\r|\n)/gm, " "); var title = body.valMatch(/(.*)<\/title>/, 2); @@ -20,6 +22,14 @@ var link = function(dbot) { } } }); + + page.on('data', function(chunk) { + size += chunk.length; + if(size > limit) { + page.abort(); + event.reply('request too big, fuck off'); + } + }); }; var commands = {