3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-24 04:49:25 +01:00

that might do it

This commit is contained in:
reality 2013-08-21 15:11:06 +00:00
parent f2755468e0
commit 71b7b3c570

View File

@ -5,7 +5,8 @@
var _ = require('underscore')._, var _ = require('underscore')._,
request = require('request'), request = require('request'),
crypto = require('crypto'); crypto = require('crypto'),
gm = require('gm');
var imgur = function(dbot) { var imgur = function(dbot) {
this.internalAPI = { this.internalAPI = {
@ -79,7 +80,9 @@ var imgur = function(dbot) {
dbot.db.imgur.totalHttpRequests += 1; dbot.db.imgur.totalHttpRequests += 1;
var image = request(testUrl, function(error, response, body) { var image = request(testUrl, function(error, response, body) {
// 492 is body.length of a removed image // 492 is body.length of a removed image
if(!error && response.statusCode == 200 && body.length != 492) { var img = gm(response);
if(!error && response.statusCode == 200 && body.length != 492 &&
img.height > 300 && img.width > 300) {
dbot.db.imgur.totalImages += 1; dbot.db.imgur.totalImages += 1;
var hash = crypto.createHash('md5').update(body).digest("hex"); var hash = crypto.createHash('md5').update(body).digest("hex");
if(_.has(dbot.modules, 'quotes')){ if(_.has(dbot.modules, 'quotes')){
@ -153,21 +156,12 @@ var imgur = function(dbot) {
this.commands = { this.commands = {
'~ri': function(event) { '~ri': function(event) {
var getImage = function() {
this.api.getRandomImage(function(link, slug) { this.api.getRandomImage(function(link, slug) {
this.api.getImageInfo(slug, function(imgData) { this.api.getImageInfo(slug, function(imgData) {
if(imgData && _.has(imgData, 'data')
&& imgData.data.height > 300 && imgData.data.width > 300) {
var info = this.internalAPI.infoString(imgData); var info = this.internalAPI.infoString(imgData);
event.reply(event.user + ': ' + link + ' [' + info + ']'); event.reply(event.user + ': ' + link + ' [' + info + ']');
} else {
getImage();
}
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
}.bind(this);
getImage();
} }
} }