3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-18 00:22:35 +01:00

faster and includes uppercase characters (which are apparently the larger images)

This commit is contained in:
reality 2013-04-10 20:14:54 +00:00
parent d82108de83
commit 8f977f8923

View File

@ -9,8 +9,13 @@ var _ = require('underscore')._,
var imgur = function(dbot) { var imgur = function(dbot) {
this.api = { this.api = {
'getRandomImage': function(callback) { '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/' + var testUrl = 'http://i.imgur.com/' +
Math.random().toString(36).substr(2,6) + random(5) +
'.png'; '.png';
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