undo imgur async because i dunno how to do auth yet, added redditbooru async

This commit is contained in:
Dalton
2018-12-07 20:44:54 -08:00
parent 1816785d52
commit bb379e25d8

17
bot.js
View File

@@ -131,23 +131,22 @@ function bestEffortRequest(subpage, page_max) {
return reddit_response; return reddit_response;
} }
let imgur_url = 'https://api.imgur.com/3/gallery/r/' + subpage + '/time/' + getRandomInt(1, page_max);
let imgur_response; let imgur_response;
if (page_max) { if (page_max) {
imgur_response = asyncSiteRequest(imgur_url, handleImgurJson); imgur_response = imgurRequest(subpage, page_max);
if (imgur_response) { if (imgur_response) {
return imgur_response return imgur_response
} }
} }
let redditbooru_response = redditbooruRequest(subpage); let redditbooru_url = "https://" + subpage + ".redditbooru.com/images/?limit=1000";
let redditbooru_response = asyncSiteRequest(redditbooru_url, handleRedditBooruJson);
if (redditbooru_response) { if (redditbooru_response) {
return redditbooru_response return redditbooru_response
} }
// leaving this here for debug. // leaving this here for debug.
sendToBotTestingChannel('reddit:' + reddit_response + '\nimgur:' + imgur_response + '\nredditbooru:' + redditbooru_response); // sendToBotTestingChannel('reddit:' + reddit_response + '\nimgur:' + imgur_response + '\nredditbooru:' + redditbooru_response);
return "I couldn't find that, sauce?"; return "I couldn't find that, sauce?";
} }
@@ -200,7 +199,6 @@ function handleRedditJson(data) {
// Abstracted Imgur Json media grab. // Abstracted Imgur Json media grab.
function handleImgurJson(data) { function handleImgurJson(data) {
let json = data.json(); let json = data.json();
let json_data = json.data[getRandomInt(0, json.data.length - 1)]; let json_data = json.data[getRandomInt(0, json.data.length - 1)];
if (json_data) { if (json_data) {
@@ -208,6 +206,13 @@ function handleImgurJson(data) {
} }
} }
// Abstracted Reddit Booru Json media grab.
function handleRedditBooruJson(data) {
let json = data.json();
return json[getRandomInt(0, json.length)].cdnUrl;
}
// Makes an async url request with the provided function: 'process'. // Makes an async url request with the provided function: 'process'.
function asyncSiteRequest(url, process) { function asyncSiteRequest(url, process) {