refactor
This commit is contained in:
22
bot.js
22
bot.js
@@ -226,12 +226,21 @@ function handleRedditBooruJson(data) {
|
|||||||
return json[getRandomInt(0, json.length)].cdnUrl;
|
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'.
|
// Makes an async url request with the provided function: 'process'.
|
||||||
async function asyncReddit(message) {
|
async function asyncReddit(channelMessage) {
|
||||||
|
|
||||||
// test command for async site request
|
// test command for async site request
|
||||||
|
|
||||||
let messageSplit = message.content.substring(2).split(' ');
|
let messageSplit = channelMessage.content.substring(2).split(' ');
|
||||||
if (messageSplit.length === 2) {
|
if (messageSplit.length === 2) {
|
||||||
let reddit_url = "https://www.reddit.com/r/"
|
let reddit_url = "https://www.reddit.com/r/"
|
||||||
+ messageSplit[1].replace(/[^a-zA-Z0-9_\-]+/g, '')
|
+ 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
|
// subreddit request
|
||||||
function subredditRequest(subreddit) {
|
function subredditRequest(subreddit) {
|
||||||
let multiSubreddit = subreddit.split(',');
|
let multiSubreddit = subreddit.split(',');
|
||||||
|
Reference in New Issue
Block a user