forked from GitHub/dbot
count api/http/images generated by imgur
This commit is contained in:
parent
3b5ef9f55e
commit
2f11e9fa0e
@ -7,6 +7,7 @@ var _ = require('underscore')._,
|
|||||||
request = require('request');
|
request = require('request');
|
||||||
|
|
||||||
var imgur = function(dbot) {
|
var imgur = function(dbot) {
|
||||||
|
this.db = dbot.db.imgur;
|
||||||
this.internalAPI = {
|
this.internalAPI = {
|
||||||
'infoString': function(imgData) {
|
'infoString': function(imgData) {
|
||||||
info = '';
|
info = '';
|
||||||
@ -29,7 +30,7 @@ var imgur = function(dbot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}.bind(this)
|
||||||
};
|
};
|
||||||
|
|
||||||
this.api = {
|
this.api = {
|
||||||
@ -44,9 +45,11 @@ var imgur = function(dbot) {
|
|||||||
var testUrl = 'http://i.imgur.com/' +
|
var testUrl = 'http://i.imgur.com/' +
|
||||||
testSlug +
|
testSlug +
|
||||||
'.' + ext[_.random(0, ext.length - 1)];
|
'.' + ext[_.random(0, ext.length - 1)];
|
||||||
|
this.db.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) {
|
if(!error && response.statusCode == 200 && body.length != 492) {
|
||||||
|
this.db.totalImages += 1;
|
||||||
callback(testUrl, testSlug);
|
callback(testUrl, testSlug);
|
||||||
} else {
|
} else {
|
||||||
this.api.getRandomImage(callback);
|
this.api.getRandomImage(callback);
|
||||||
@ -68,8 +71,9 @@ var imgur = function(dbot) {
|
|||||||
'Authorization': 'Client-ID 86fd3a8da348b65'
|
'Authorization': 'Client-ID 86fd3a8da348b65'
|
||||||
}
|
}
|
||||||
}, function(err, response, body) {
|
}, function(err, response, body) {
|
||||||
|
this.db.totalApiRequests += 1;
|
||||||
callback(body);
|
callback(body);
|
||||||
});
|
}.bind(this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.api['getRandomImage'].external = true;
|
this.api['getRandomImage'].external = true;
|
||||||
@ -99,6 +103,9 @@ var imgur = function(dbot) {
|
|||||||
}.bind(this);
|
}.bind(this);
|
||||||
dbot.api.link.addHandler(this.name, /https?:\/\/i\.imgur\.com\/([a-zA-Z0-9]+)\.([jpg|png|gif])/, imgurHandler);
|
dbot.api.link.addHandler(this.name, /https?:\/\/i\.imgur\.com\/([a-zA-Z0-9]+)\.([jpg|png|gif])/, imgurHandler);
|
||||||
dbot.api.link.addHandler(this.name, /https?:\/\/imgur\.com\/([a-zA-Z0-9]+)/, imgurHandler);
|
dbot.api.link.addHandler(this.name, /https?:\/\/imgur\.com\/([a-zA-Z0-9]+)/, imgurHandler);
|
||||||
|
if(!_.has(dbot.db.imgur, 'totalHttpRequests')) dbot.db.imgur.totalHttpRequests = 0;
|
||||||
|
if(!_.has(dbot.db.imgur, 'totalApiRequests')) dbot.db.imgur.totalApiRequests = 0;
|
||||||
|
if(!_.has(dbot.db.imgur, 'totalImages')) dbot.db.imgur.totalImages = 0;
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user