This commit is contained in:
Dalton
2018-12-11 22:48:42 -08:00
parent 8bbf4baa3c
commit 98b2f58d35

22
bot.js
View File

@@ -226,12 +226,21 @@ function handleRedditBooruJson(data) {
return json[getRandomInt(0, json.length)].cdnUrl;
}
async function loadJson(url) {
let response = await fetch(url);
if (response.status == 200) {
return response.json();
} else {
throw new HttpError(response);
}
}
// Makes an async url request with the provided function: 'process'.
async function asyncReddit(message) {
async function asyncReddit(channelMessage) {
// test command for async site request
let messageSplit = message.content.substring(2).split(' ');
let messageSplit = channelMessage.content.substring(2).split(' ');
if (messageSplit.length === 2) {
let reddit_url = "https://www.reddit.com/r/"
+ messageSplit[1].replace(/[^a-zA-Z0-9_\-]+/g, '')
@@ -245,15 +254,6 @@ async function asyncReddit(message) {
}
}
async function loadJson(url) {
let response = await fetch(url);
if (response.status == 200) {
return response.json();
} else {
throw new HttpError(response);
}
}
// subreddit request
function subredditRequest(subreddit) {
let multiSubreddit = subreddit.split(',');