mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-27 14:18:36 +02:00
Use imgur albums for random image commands
This commit is contained in:
@@ -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, '')
|
||||
|
||||
Reference in New Issue
Block a user