don't check json if reddit doesn't exist

This commit is contained in:
Dalton
2018-12-07 20:54:31 -08:00
parent c0bd38c7c7
commit f83e6f29f7

10
bot.js
View File

@@ -186,11 +186,13 @@ function imgurRequest(subreddit, page_max) {
// Abstracted Reddit Json media grab.
function handleRedditJson(data) {
let json = data.json();
for (let i = 0; i < json.data.children.length; i++) {
let rand = getRandomInt(0, json.data.children.length - 1);
if(json.data.children) {
for (let 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;
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;
}
}
}
// What if we don't find anything i.e. r/dogs but its valid subreddit.