From 0efa8d021771338d475e6dee26f8d56edba4ff0a Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 21 Aug 2013 15:18:08 +0000 Subject: [PATCH] that might do it --- modules/imgur/imgur.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/modules/imgur/imgur.js b/modules/imgur/imgur.js index 948951d..b765217 100644 --- a/modules/imgur/imgur.js +++ b/modules/imgur/imgur.js @@ -80,27 +80,28 @@ var imgur = function(dbot) { dbot.db.imgur.totalHttpRequests += 1; var image = request(testUrl, function(error, response, body) { // 492 is body.length of a removed image - var img = gm(body); - if(!error && response.statusCode == 200 && body.length != 492 && - img.height > 300 && img.width > 300) { - dbot.db.imgur.totalImages += 1; - var hash = crypto.createHash('md5').update(body).digest("hex"); - if(_.has(dbot.modules, 'quotes')){ - // autoadd: {"abcdef": "facebookman"} - if(_.has(dbot.config.modules.imgur.autoadd,hash)){ - var category = dbot.config.imgur.autoadd[hash]; - if (_.contains(category, testUrl)){ - // there's probably less than 62^5 chance of this happening - } else { - dbot.api.quotes.addQuote(category, testUrl, - dbot.config.name, function() { }); + gm(body).size(function(err, val) { + if(!error && response.statusCode == 200 && body.length != 492 && + val && val.height > 300 && val.width > 300) { + dbot.db.imgur.totalImages += 1; + var hash = crypto.createHash('md5').update(body).digest("hex"); + if(_.has(dbot.modules, 'quotes')){ + // autoadd: {"abcdef": "facebookman"} + if(_.has(dbot.config.modules.imgur.autoadd,hash)){ + var category = dbot.config.imgur.autoadd[hash]; + if (_.contains(category, testUrl)){ + // there's probably less than 62^5 chance of this happening + } else { + dbot.api.quotes.addQuote(category, testUrl, + dbot.config.name, function() { }); + } } } + callback(testUrl, testSlug, hash); + } else { + this.api.getRandomImage(callback); } - callback(testUrl, testSlug, hash); - } else { - this.api.getRandomImage(callback); - } + }.bind(this)); }.bind(this)); },