testing async
This commit is contained in:
23
bot.js
23
bot.js
@@ -101,7 +101,7 @@ function noQuestion() {
|
|||||||
// 3. RedditBooru
|
// 3. RedditBooru
|
||||||
function bestEffortRequest(subpage, page_max) {
|
function bestEffortRequest(subpage, page_max) {
|
||||||
|
|
||||||
let reddit_response = subredditRequest(subpage);
|
let reddit_response = asyncRedditRequest(subpage);
|
||||||
if(reddit_response) { return reddit_response; }
|
if(reddit_response) { return reddit_response; }
|
||||||
|
|
||||||
let imgur_response;
|
let imgur_response;
|
||||||
@@ -147,6 +147,27 @@ function imgurRequest(subreddit, page_max) {
|
|||||||
return returnText;
|
return returnText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dalton async reddit?
|
||||||
|
function asyncRedditRequest(requested_item) {
|
||||||
|
|
||||||
|
let url= "https://www.reddit.com/r/" + requested_item + "/.json?show=all&count=25&limit=100";
|
||||||
|
|
||||||
|
fetch(url)
|
||||||
|
.then(data => {
|
||||||
|
let json = data.json();
|
||||||
|
for(i = 0; i < json.data.children.length; i++) {
|
||||||
|
let rand = getRandomInt(0, json.data.children.length - 1);
|
||||||
|
|
||||||
|
if (json.data.children[rand].data.post_hint === "image" || json.data.children[rand].data.post_hint === "link" || json.data.children.data.post_hint === "rich:video") {
|
||||||
|
return json.data.children[rand].data.url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
client.channels.get('357365312620068874').send(error.message);
|
||||||
|
return ""; })
|
||||||
|
}
|
||||||
|
|
||||||
// subreddit request
|
// subreddit request
|
||||||
function subredditRequest(subreddit) {
|
function subredditRequest(subreddit) {
|
||||||
var multiSubreddit = subreddit.split(',');
|
var multiSubreddit = subreddit.split(',');
|
||||||
|
Reference in New Issue
Block a user