Use imgur albums for random image commands

This commit is contained in:
Daniel Odendahl Jr
2018-03-06 23:34:58 +00:00
parent cc37c65cf7
commit 1fa68a3497
26 changed files with 182 additions and 313 deletions
+10
View File
@@ -1,4 +1,6 @@
const snekfetch = require('snekfetch');
const crypto = require('crypto');
const { IMGUR_KEY } = process.env;
const yes = ['yes', 'y', 'ye', 'yeah', 'yup', 'yea'];
const no = ['no', 'n', 'nah', 'nope'];
@@ -60,6 +62,14 @@ class Util {
return crypto.createHash(algorithm).update(text).digest('hex');
}
static async randomFromImgurAlbum(album) {
const { body } = await snekfetch
.get(`https://api.imgur.com/3/album/${album}`)
.set({ Authorization: `Client-ID ${IMGUR_KEY}` });
if (!body.data.images.length) return null;
return body.data.images[Math.floor(Math.random() * body.data.images.length)].link;
}
static cleanXML(text) {
return text
.replace(/<br \/>/g, '')