From df7d4149c616ba582c51f549c7b3baea9aaf1c45 Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 10 Sep 2013 16:29:23 +0000 Subject: [PATCH] ~ssri --- modules/command/api.js | 1 - modules/imgur/imgur.js | 28 +++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/modules/command/api.js b/modules/command/api.js index e42d3cb..5a757a5 100644 --- a/modules/command/api.js +++ b/modules/command/api.js @@ -26,7 +26,6 @@ var api = function(dbot) { }) .pluck('name') .value()); - console.log(allowedNicks); } if(!_.include(allowedNicks, user.primaryNick)) { diff --git a/modules/imgur/imgur.js b/modules/imgur/imgur.js index 4047290..74a09c9 100644 --- a/modules/imgur/imgur.js +++ b/modules/imgur/imgur.js @@ -79,7 +79,8 @@ var imgur = function(dbot) { testSlug + '.' + ext[_.random(0, ext.length - 1)]; dbot.db.imgur.totalHttpRequests += 1; - var image = request(testUrl, function(error, response, body) { + + request(testUrl, function(error, response, body) { // 492 is body.length of a removed image if(!error && response.statusCode == 200 && body.length != 492) { dbot.db.imgur.totalImages += 1; @@ -103,6 +104,18 @@ var imgur = function(dbot) { }.bind(this)); }, + 'getGoodRandomImage': function(callback) { + this.api.getRandomImage(function(url, slug, hash) { + this.api.getImageInfo(slug, function(imgData) { + if(imgData.data && imgData.data.height > 500 && imgData.data.width > 500) { + callback(url, imgData); + } else { + this.api.getGoodRandomImage(callback); + } + }.bind(this)); + }.bind(this)); + }, + 'getImageInfoString': function(slug, callback) { this.api.getImageInfo(slug, function(imgData) { callback(this.internalAPI.infoString(imgData)); @@ -167,6 +180,19 @@ var imgur = function(dbot) { }.bind(this)); }, + // Super Slow RI + '~ssri': function(event) { + var local = event.user; + if(event.params[1]) { + local = event.params.splice(1, event.params.length - 1).join(' ').trim(); + } + this.api.getGoodRandomImage(function(link, imgData) { + var info = this.internalAPI.infoString(imgData); + event.reply(local + ': ' + link + ' [' + info + ']'); + }.bind(this)); + }, + + // Super RI '~sri': function(event) { var local = event.user; if(event.params[1]) {