ImgurAlbumCommand

This commit is contained in:
Dragon Fire
2018-09-03 16:16:05 -04:00
parent 0b9c8241bb
commit 1b8fa13b44
20 changed files with 56 additions and 113 deletions
+7 -26
View File
@@ -1,8 +1,7 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const { IMGUR_KEY, FIDGET_ALBUM_ID } = process.env;
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { FIDGET_ALBUM_ID } = process.env;
module.exports = class FidgetCommand extends Command {
module.exports = class FidgetCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'fidget',
@@ -10,30 +9,12 @@ module.exports = class FidgetCommand extends Command {
group: 'random',
memberName: 'fidget',
description: 'Responds with a random image of Fidget.',
clientPermissions: ['ATTACH_FILES']
clientPermissions: ['ATTACH_FILES'],
albumID: FIDGET_ALBUM_ID
});
this.cache = null;
}
async run(msg) {
try {
const nimbat = await this.random();
if (!nimbat) return msg.reply('This album has no images...');
return msg.say({ files: [nimbat] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
async random() {
if (this.cache) return this.cache[Math.floor(Math.random() * this.cache.length)].link;
const { body } = await request
.get(`https://api.imgur.com/3/album/${FIDGET_ALBUM_ID}`)
.set({ Authorization: `Client-ID ${IMGUR_KEY}` });
if (!body.data.images.length) return null;
this.cache = body.data.images;
setTimeout(() => { this.cache = null; }, 3.6e+6);
return body.data.images[Math.floor(Math.random() * body.data.images.length)].link;
generateText() {
return 'Aren\'t Nimbats adorable?';
}
};
+7 -26
View File
@@ -1,38 +1,19 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const { IMGUR_KEY, POSTER_ALBUM_ID } = process.env;
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { POSTER_ALBUM_ID } = process.env;
module.exports = class MemeCommand extends Command {
module.exports = class MemeCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'meme',
group: 'random',
memberName: 'meme',
description: 'Responds with a random meme.',
clientPermissions: ['ATTACH_FILES']
clientPermissions: ['ATTACH_FILES'],
albumID: POSTER_ALBUM_ID
});
this.cache = null;
}
async run(msg) {
try {
const meme = await this.random();
if (!meme) return msg.reply('This album has no images...');
return msg.say({ files: [meme] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
async random() {
if (this.cache) return this.cache[Math.floor(Math.random() * this.cache.length)].link;
const { body } = await request
.get(`https://api.imgur.com/3/album/${POSTER_ALBUM_ID}`)
.set({ Authorization: `Client-ID ${IMGUR_KEY}` });
if (!body.data.images.length) return null;
this.cache = body.data.images;
setTimeout(() => { this.cache = null; }, 3.6e+6);
return body.data.images[Math.floor(Math.random() * body.data.images.length)].link;
generateText() {
return null;
}
};
+7 -26
View File
@@ -1,8 +1,7 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const { IMGUR_KEY, XIAO_ALBUM_ID } = process.env;
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { XIAO_ALBUM_ID } = process.env;
module.exports = class XiaoCommand extends Command {
module.exports = class XiaoCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'xiao',
@@ -10,30 +9,12 @@ module.exports = class XiaoCommand extends Command {
group: 'random',
memberName: 'xiao',
description: 'Responds with a random image of Xiao Pai.',
clientPermissions: ['ATTACH_FILES']
clientPermissions: ['ATTACH_FILES'],
albumID: XIAO_ALBUM_ID
});
this.cache = null;
}
async run(msg) {
try {
const xiao = await this.random();
if (!xiao) return msg.reply('This album has no images...');
return msg.say({ files: [xiao] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
async random() {
if (this.cache) return this.cache[Math.floor(Math.random() * this.cache.length)].link;
const { body } = await request
.get(`https://api.imgur.com/3/album/${XIAO_ALBUM_ID}`)
.set({ Authorization: `Client-ID ${IMGUR_KEY}` });
if (!body.data.images.length) return null;
this.cache = body.data.images;
setTimeout(() => { this.cache = null; }, 3.6e+6);
return body.data.images[Math.floor(Math.random() * body.data.images.length)].link;
generateText() {
return 'It\'s me, yes?';
}
};