try new async
This commit is contained in:
16
bot.js
16
bot.js
@@ -192,8 +192,8 @@ function imgurRequest(subreddit, page_max) {
|
||||
|
||||
// Abstracted Reddit Json media grab.
|
||||
// todo I think since it's randomly picking indices but children.length * 2 times, it's missing rare items.
|
||||
function handleRedditJson(data) {
|
||||
let json = data.json();
|
||||
function handleRedditJson(json) {
|
||||
//let json = data.json();
|
||||
if (json.data) {
|
||||
sendToBotTestingChannel("json data pressseeeeent");
|
||||
let url_list = [];
|
||||
@@ -242,6 +242,15 @@ function asyncSiteRequest(url, process) {
|
||||
})
|
||||
}
|
||||
|
||||
async function loadJson(url) {
|
||||
let response = await fetch(url);
|
||||
if (response.status == 200) {
|
||||
return response.json();
|
||||
} else {
|
||||
throw new HttpError(response);
|
||||
}
|
||||
}
|
||||
|
||||
// subreddit request
|
||||
function subredditRequest(subreddit) {
|
||||
let multiSubreddit = subreddit.split(',');
|
||||
@@ -652,7 +661,8 @@ client.on('message', message => {
|
||||
if (messageSplit.length === 2) {
|
||||
let redditToSummon = messageSplit[1].replace(/[^a-zA-Z0-9_\-]+/g, '');
|
||||
let reddit_url = "https://www.reddit.com/r/" + redditToSummon + "/.json?show=all&count=25&limit=100";
|
||||
let reddit_response = asyncSiteRequest(reddit_url, handleRedditJson);
|
||||
|
||||
let reddit_response = handleRedditJson(loadJson(reddit_url));
|
||||
sendToBotTestingChannel("reddit response:" + reddit_response);
|
||||
if (reddit_response) {
|
||||
//sendToBotTestingChannel("found content on reddit:" + reddit_response);
|
||||
|
Reference in New Issue
Block a user