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) {
|
||||
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 => {
|
||||
|
Reference in New Issue
Block a user