added counter
This commit is contained in:
8
bot.js
8
bot.js
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user