mirror of
https://github.com/reality/dbot.git
synced 2025-01-11 20:42:37 +01:00
Show info about the imgur url on the random page
This commit is contained in:
parent
37a37c97b9
commit
3b5ef9f55e
@ -9,12 +9,11 @@ var _ = require('underscore')._,
|
|||||||
var imgur = function(dbot) {
|
var imgur = function(dbot) {
|
||||||
this.internalAPI = {
|
this.internalAPI = {
|
||||||
'infoString': function(imgData) {
|
'infoString': function(imgData) {
|
||||||
info = null;
|
info = '';
|
||||||
if(imgData && _.has(imgData, 'data')) {
|
if(imgData && _.has(imgData, 'data')) {
|
||||||
imgData = imgData.data;
|
imgData = imgData.data;
|
||||||
info = '[';
|
|
||||||
if(imgData.title) {
|
if(imgData.title) {
|
||||||
info += imgData.title + '][';
|
info += imgData.title + ' - ';
|
||||||
}
|
}
|
||||||
if(imgData.type) {
|
if(imgData.type) {
|
||||||
if(imgData.animated) {
|
if(imgData.animated) {
|
||||||
@ -26,7 +25,7 @@ var imgur = function(dbot) {
|
|||||||
info += 'an image with ';
|
info += 'an image with ';
|
||||||
}
|
}
|
||||||
info += imgData.views + ' views (';
|
info += imgData.views + ' views (';
|
||||||
info += imgData.width + 'x' + imgData.height + ')].';
|
info += imgData.width + 'x' + imgData.height + ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
@ -55,6 +54,12 @@ var imgur = function(dbot) {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'getImageInfoString': function(slug, callback) {
|
||||||
|
this.api.getImageInfo(slug, function(imgData) {
|
||||||
|
callback(this.internalAPI.infoString(imgData));
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
'getImageInfo': function(slug, callback) {
|
'getImageInfo': function(slug, callback) {
|
||||||
request.get({
|
request.get({
|
||||||
'url': 'https://api.imgur.com/3/image/' + slug + '.json',
|
'url': 'https://api.imgur.com/3/image/' + slug + '.json',
|
||||||
@ -69,13 +74,15 @@ var imgur = function(dbot) {
|
|||||||
};
|
};
|
||||||
this.api['getRandomImage'].external = true;
|
this.api['getRandomImage'].external = true;
|
||||||
this.api['getRandomImage'].extMap = [ 'callback' ];
|
this.api['getRandomImage'].extMap = [ 'callback' ];
|
||||||
|
this.api['getImageInfoString'].external = true;
|
||||||
|
this.api['getImageInfoString'].extMap = [ 'slug', 'callback' ];
|
||||||
|
|
||||||
this.commands = {
|
this.commands = {
|
||||||
'~ri': function(event) {
|
'~ri': function(event) {
|
||||||
this.api.getRandomImage(function(link, slug) {
|
this.api.getRandomImage(function(link, slug) {
|
||||||
this.api.getImageInfo(slug, function(imgData) {
|
this.api.getImageInfo(slug, function(imgData) {
|
||||||
var info = this.internalAPI.infoString(imgData);
|
var info = this.internalAPI.infoString(imgData);
|
||||||
event.reply(event.user + ': ' + link + ' ' + info);
|
event.reply(event.user + ': ' + link + ' [' + info + ']');
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
@ -86,7 +93,7 @@ var imgur = function(dbot) {
|
|||||||
if(matches[1]) {
|
if(matches[1]) {
|
||||||
this.api.getImageInfo(matches[1], function(imgData) {
|
this.api.getImageInfo(matches[1], function(imgData) {
|
||||||
var info = this.internalAPI.infoString(imgData);
|
var info = this.internalAPI.infoString(imgData);
|
||||||
if(info) event.reply(info);
|
if(info) event.reply('[' + info + ']');
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
border-bottom-right-radius:5px;
|
border-bottom-right-radius:5px;
|
||||||
border-top-right-radius:5px;
|
border-top-right-radius:5px;
|
||||||
color:#85bf25;
|
color:#85bf25;
|
||||||
display:none;
|
|
||||||
font-family:sans-serif;
|
font-family:sans-serif;
|
||||||
font-weight:700;
|
font-weight:700;
|
||||||
left:0;
|
left:0;
|
||||||
|
@ -7,15 +7,19 @@ html(lang='en')
|
|||||||
title random imgur
|
title random imgur
|
||||||
script
|
script
|
||||||
var count = 0;
|
var count = 0;
|
||||||
function wat() {
|
function getNewImage() {
|
||||||
count += 1;
|
count += 1;
|
||||||
$('#loading').text('Loading image ' + count);
|
$('#loading').text('Loading image ' + count + '...');
|
||||||
$('#loading').show();
|
$('#image').load(function(){});
|
||||||
$('#image').load(function(){$('#loading').hide(); console.log('loaded')});
|
$.get("/api/imgur/getRandomImage", function(d) {
|
||||||
$.get("/api/imgur/getRandomImage", function(d) {$('#image').attr('src', d.data[0])}, "json");
|
$('#image').attr('src', d.data[0]);
|
||||||
};
|
$.get("/api/imgur/getImageInfoString", { 'slug': d.data[1] }, function(info) {
|
||||||
$(wat());
|
$("#loading").text(count + ': ' + info.data[0]);
|
||||||
$(document).on('keydown', function(e){(e.which==32)&&(wat()) });
|
}, "json");
|
||||||
|
}, "json");
|
||||||
|
}
|
||||||
|
$(getNewImage());
|
||||||
|
$(document).on('keydown', function(e){(e.which==32)&&(getNewImage()) });
|
||||||
body
|
body
|
||||||
div#loading Loading Image
|
div#loading Loading Image
|
||||||
div#container
|
div#container
|
||||||
|
Loading…
Reference in New Issue
Block a user