mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 22:39:26 +01:00
37 lines
957 B
JavaScript
37 lines
957 B
JavaScript
/**
|
|
* Module Name: imgur
|
|
* Description: Various imgur functionality
|
|
*/
|
|
|
|
var _ = require('underscore')._,
|
|
request = require('request');
|
|
|
|
var imgur = function(dbot) {
|
|
this.api = {
|
|
'getRandomImage': function(callback) {
|
|
var testUrl = 'http://i.imgur.com/' +
|
|
Math.random().toString(36).substr(2,6) +
|
|
'.jpg';
|
|
var image = request(testUrl, function(error, response, body) {
|
|
if(!error && response.statusCode == 200) {
|
|
callback(testUrl);
|
|
} else {
|
|
this.api.getRandomImage(callback);
|
|
}
|
|
}.bind(this));
|
|
}
|
|
};
|
|
|
|
this.commands = {
|
|
'~randomimgur': function(event) {
|
|
this.api.getRandomImage(function(link) {
|
|
event.reply(event.user + ': ' + link);
|
|
});
|
|
}
|
|
}
|
|
};
|
|
|
|
exports.fetch = function(dbot) {
|
|
return new imgur(dbot);
|
|
}
|