From 8f977f89231816762cb102362edce6da3ff756f0 Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 10 Apr 2013 20:14:54 +0000 Subject: [PATCH] faster and includes uppercase characters (which are apparently the larger images) --- modules/imgur/imgur.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/imgur/imgur.js b/modules/imgur/imgur.js index ac5a578..fb4c264 100644 --- a/modules/imgur/imgur.js +++ b/modules/imgur/imgur.js @@ -9,8 +9,13 @@ var _ = require('underscore')._, var imgur = function(dbot) { this.api = { 'getRandomImage': function(callback) { + var random = function(len) { + var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; + return len ? chars.charAt(~~(Math.random()*chars.length)) + random(len-1) : ""; + }; + var testUrl = 'http://i.imgur.com/' + - Math.random().toString(36).substr(2,6) + + random(5) + '.png'; var image = request(testUrl, function(error, response, body) { // 492 is body.length of a removed image