better handle reddit json logic
This commit is contained in:
13
bot.js
13
bot.js
@@ -188,13 +188,14 @@ function imgurRequest(subreddit, page_max) {
|
|||||||
function handleRedditJson(data) {
|
function handleRedditJson(data) {
|
||||||
let json = data.json();
|
let json = data.json();
|
||||||
if (json.data) {
|
if (json.data) {
|
||||||
for (let i = 0; i < json.data.children.length * 2; i++) {
|
sendToBotTestingChannel("json data pressseeeeent");
|
||||||
let rand = getRandomInt(0, json.data.children.length - 1);
|
let url_list = [];
|
||||||
|
for (let i = 0; i < json.data.children.length; i++) {
|
||||||
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") {
|
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") {
|
||||||
return json.data.children[rand].data.url;
|
url_list.push(json.data.children[i].data.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return url_list[getRandomInt(0, url_list.length - 1)];
|
||||||
} else {
|
} else {
|
||||||
sendToBotTestingChannel("json data:" + json.data);
|
sendToBotTestingChannel("json data:" + json.data);
|
||||||
}
|
}
|
||||||
@@ -223,8 +224,6 @@ function asyncSiteRequest(url, process) {
|
|||||||
|
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
sendToBotTestingChannel("data.data.children::" + data.data.children);
|
|
||||||
|
|
||||||
return process(data);
|
return process(data);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
Reference in New Issue
Block a user