better handle reddit json logic

This commit is contained in:
Dalton
2018-12-11 21:16:02 -08:00
parent 79704aaa83
commit a3ad795ac2

13
bot.js
View File

@@ -188,13 +188,14 @@ function imgurRequest(subreddit, page_max) {
function handleRedditJson(data) {
let json = data.json();
if (json.data) {
for (let i = 0; i < json.data.children.length * 2; 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;
sendToBotTestingChannel("json data pressseeeeent");
let url_list = [];
for (let i = 0; i < json.data.children.length; i++) {
if (json.data.children[i].data.post_hint === "image" || json.data.children[i].data.post_hint === "link" || json.data.children[i].data.post_hint === "rich:video") {
url_list.push(json.data.children[i].data.url);
}
}
return url_list[getRandomInt(0, url_list.length - 1)];
} else {
sendToBotTestingChannel("json data:" + json.data);
}
@@ -223,8 +224,6 @@ function asyncSiteRequest(url, process) {
fetch(url)
.then(data => {
sendToBotTestingChannel("data.data.children::" + data.data.children);
return process(data);
})
.catch(error => {