From 48c9249a0eded99d67ccc1813b9e834f1caf0469 Mon Sep 17 00:00:00 2001 From: Dalton Date: Tue, 11 Dec 2018 23:44:18 -0800 Subject: [PATCH] imgur auth attempt --- bot.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bot.js b/bot.js index 59bb3af..e4bcf3d 100644 --- a/bot.js +++ b/bot.js @@ -216,8 +216,14 @@ function getUrlListFromRedditBooru(json) { } // Async request of a page that returns JSON. -async function loadJson(url) { - let response = await fetch(url); +async function loadJson(url, auth) { + + let response; + if (auth) { + response = await fetch(url, auth); + } else { + response = await fetch(url); + } if (response.status === 200) { return response.json(); } else { @@ -238,7 +244,10 @@ async function asyncImageRequest(channelMessage) { //collect all the json let image_url_list = []; let reddit_json = await loadJson("https://www.reddit.com/r/" + requested_item + "/.json?show=all&count=25&limit=100"); - let imgur_json = await loadJson('https://api.imgur.com/3/gallery/r/' + requested_item + '/time/' + getRandomInt(1, 5)); + let imgur_json = await loadJson( + 'https://api.imgur.com/3/gallery/r/' + requested_item + '/time/' + getRandomInt(1, 5), + {'Authorization': 'Client-ID ' + auth.imgur} + ); // todo need to check config to see if it's a valid booruuuuu //let redditbooru_json = await loadJson("https://" + requested_item + ".redditbooru.com/images/?limit=1000");