undo imgur async because i dunno how to do auth yet, added redditbooru async
This commit is contained in:
17
bot.js
17
bot.js
@@ -131,23 +131,22 @@ function bestEffortRequest(subpage, page_max) {
|
||||
return reddit_response;
|
||||
}
|
||||
|
||||
let imgur_url = 'https://api.imgur.com/3/gallery/r/' + subpage + '/time/' + getRandomInt(1, page_max);
|
||||
let imgur_response;
|
||||
if (page_max) {
|
||||
imgur_response = asyncSiteRequest(imgur_url, handleImgurJson);
|
||||
imgur_response = imgurRequest(subpage, page_max);
|
||||
if (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) {
|
||||
return redditbooru_response
|
||||
}
|
||||
|
||||
// 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?";
|
||||
}
|
||||
|
||||
@@ -200,7 +199,6 @@ function handleRedditJson(data) {
|
||||
|
||||
// Abstracted Imgur Json media grab.
|
||||
function handleImgurJson(data) {
|
||||
|
||||
let json = data.json();
|
||||
let json_data = json.data[getRandomInt(0, json.data.length - 1)];
|
||||
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'.
|
||||
function asyncSiteRequest(url, process) {
|
||||
|
||||
|
Reference in New Issue
Block a user