url list rando grab fix
This commit is contained in:
11
bot.js
11
bot.js
@@ -189,12 +189,9 @@ async function getBotConfigValueFrom(key) {
|
|||||||
|
|
||||||
// Abstracted Reddit Json media grab. Will return a list of URLs!
|
// Abstracted Reddit Json media grab. Will return a list of URLs!
|
||||||
function getUrlListFromReddit(json) {
|
function getUrlListFromReddit(json) {
|
||||||
|
|
||||||
let url_list = [];
|
let url_list = [];
|
||||||
for (let i = 0; i < json.data.children.length; i++) {
|
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") {
|
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);
|
url_list.push(json.data.children[i].data.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,16 +200,14 @@ function getUrlListFromReddit(json) {
|
|||||||
return url_list;
|
return url_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Abstracted Imgur Json media grab.
|
// Abstracted Imgur Json media grab. Will return a list of URLs!
|
||||||
function getUrlListFromImgur(json) {
|
function getUrlListFromImgur(json) {
|
||||||
|
|
||||||
let url_list = [];
|
let url_list = [];
|
||||||
for (let i = 0; i < json.data.length; i++) {
|
for (let i = 0; i < json.data.length; i++) {
|
||||||
if (json.data[i]) {
|
if (json.data[i]) {
|
||||||
url_list.push(json.data[i].link);
|
url_list.push(json.data[i].link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('imgur_list' + url_list);
|
|
||||||
return url_list;
|
return url_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +250,7 @@ async function asyncImageRequest(channelMessage) {
|
|||||||
// Split the user message
|
// Split the user message
|
||||||
let messageSplit = channelMessage.content.substring(2).split(' ');
|
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) {
|
if (messageSplit.length === 2) {
|
||||||
//regex clean the requested item to help with silly typos.
|
//regex clean the requested item to help with silly typos.
|
||||||
let requested_item = messageSplit[1].replace(/[^a-zA-Z0-9_\-]+/g, '');
|
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);
|
console.log('image concat list:' + image_url_list);
|
||||||
|
|
||||||
if (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 {
|
} else {
|
||||||
return "I couldn't find that, sauce?";
|
return "I couldn't find that, sauce?";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user