added counter

This commit is contained in:
Dalton
2018-12-07 18:06:54 -08:00
parent e19b75f37f
commit 31241c5c09

8
bot.js
View File

@@ -159,9 +159,15 @@ function subredditRequest(subreddit) {
if (req.readyState === 4 && req.status === 200) { if (req.readyState === 4 && req.status === 200) {
var json = JSON.parse(req.responseText); var json = JSON.parse(req.responseText);
let counter = 0;
while (true) { while (true) {
var i = getRandomInt(0, json.data.children.length - 1); var i = getRandomInt(0, json.data.children.length - 1);
try { try {
counter++;
if (json.data.children[i].data.post_hint === "image" || json.data.children[i].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.data.post_hint === "rich:video") {
returnText = json.data.children[i].data.url; returnText = json.data.children[i].data.url;
break; break;
@@ -173,6 +179,8 @@ function subredditRequest(subreddit) {
// continue; <-- last line in the loop... so does nothing. // continue; <-- last line in the loop... so does nothing.
client.channels.get('357365312620068874').send(error.message); client.channels.get('357365312620068874').send(error.message);
} }
if(counter > 5) { break; }g
} }
} }
}; };