url list rando grab fix

This commit is contained in:
Dalton
2018-12-12 21:04:17 -08:00
parent ceb8418854
commit 52ae1f2492

11
bot.js
View File

@@ -189,12 +189,9 @@ async function getBotConfigValueFrom(key) {
// Abstracted Reddit Json media grab. Will return a list of URLs!
function getUrlListFromReddit(json) {
let url_list = [];
for (let i = 0; i < json.data.children.length; i++) {
//console.log('reddit result:' + JSON.stringify(json.data.children[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") {
//console.log('pushing onto list');
url_list.push(json.data.children[i].data.url);
}
}
@@ -203,16 +200,14 @@ function getUrlListFromReddit(json) {
return url_list;
}
// Abstracted Imgur Json media grab.
// Abstracted Imgur Json media grab. Will return a list of URLs!
function getUrlListFromImgur(json) {
let url_list = [];
for (let i = 0; i < json.data.length; i++) {
if (json.data[i]) {
url_list.push(json.data[i].link);
}
}
console.log('imgur_list' + url_list);
return url_list;
}
@@ -255,7 +250,7 @@ async function asyncImageRequest(channelMessage) {
// Split the user message
let messageSplit = channelMessage.content.substring(2).split(' ');
// todo locked down to one search term.
// todo locked down to one search term. need to decouple the parsing.
if (messageSplit.length === 2) {
//regex clean the requested item to help with silly typos.
let requested_item = messageSplit[1].replace(/[^a-zA-Z0-9_\-]+/g, '');
@@ -272,7 +267,7 @@ async function asyncImageRequest(channelMessage) {
console.log('image concat list:' + image_url_list);
if (image_url_list) {
return image_url_list[getRandomInt(0, image_url_list - 1)];
return image_url_list[getRandomInt(0, image_url_list.length - 1)];
} else {
return "I couldn't find that, sauce?";
}