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?';
}
};
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { BLUSH_ALBUM_ID } = process.env;
module.exports = class BlushCommand extends RoleplayCommand {
module.exports = class BlushCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'blush',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { EAT_ALBUM_ID } = process.env;
module.exports = class EatCommand extends RoleplayCommand {
module.exports = class EatCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'eat',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { FIST_BUMP_ALBUM_ID } = process.env;
module.exports = class FistBumpCommand extends RoleplayCommand {
module.exports = class FistBumpCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'fist-bump',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { HIGH_FIVE_ALBUM_ID } = process.env;
module.exports = class HighFiveCommand extends RoleplayCommand {
module.exports = class HighFiveCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'high-five',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { HOLD_HANDS_ALBUM_ID } = process.env;
module.exports = class HoldHandsCommand extends RoleplayCommand {
module.exports = class HoldHandsCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'hold-hands',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { HUG_ALBUM_ID } = process.env;
module.exports = class HugCommand extends RoleplayCommand {
module.exports = class HugCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'hug',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { KILL_ALBUM_ID } = process.env;
module.exports = class KillCommand extends RoleplayCommand {
module.exports = class KillCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'kill',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { KISS_ALBUM_ID } = process.env;
module.exports = class KissCommand extends RoleplayCommand {
module.exports = class KissCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'kiss',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { PAT_ALBUM_ID } = process.env;
module.exports = class PatCommand extends RoleplayCommand {
module.exports = class PatCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'pat',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { POKE_ALBUM_ID } = process.env;
module.exports = class PokeCommand extends RoleplayCommand {
module.exports = class PokeCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'poke',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { PUNCH_ALBUM_ID } = process.env;
module.exports = class PunchCommand extends RoleplayCommand {
module.exports = class PunchCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'punch',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { SLAP_ALBUM_ID } = process.env;
module.exports = class SlapCommand extends RoleplayCommand {
module.exports = class SlapCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'slap',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { SLEEP_ALBUM_ID } = process.env;
module.exports = class SleepCommand extends RoleplayCommand {
module.exports = class SleepCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'sleep',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { WAKE_UP_ALBUM_ID } = process.env;
module.exports = class WakeUpCommand extends RoleplayCommand {
module.exports = class WakeUpCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'wake-up',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { WAVE_ALBUM_ID } = process.env;
module.exports = class WaveCommand extends RoleplayCommand {
module.exports = class WaveCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'wave',
+2 -2
View File
@@ -1,7 +1,7 @@
const RoleplayCommand = require('../../structures/commands/Roleplay');
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
const { WINK_ALBUM_ID } = process.env;
module.exports = class WinkCommand extends RoleplayCommand {
module.exports = class WinkCommand extends ImgurAlbumCommand {
constructor(client) {
super(client, {
name: 'wink',
@@ -2,7 +2,7 @@ const request = require('node-superfetch');
const Command = require('../Command');
const { IMGUR_KEY } = process.env;
module.exports = class RoleplayCommand extends Command {
module.exports = class ImgurAlbumCommand extends Command {
constructor(client, info) {
super(client, info);
@@ -21,12 +21,12 @@ module.exports = class RoleplayCommand extends Command {
}
async random() {
if (this.cache) return this.cache[Math.floor(Math.random() * this.cache.length)].link;
if (this.cache) return this.cache[Math.floor(Math.random() * this.cache.length)];
const { body } = await request
.get(`https://api.imgur.com/3/album/${this.albumID}`)
.set({ Authorization: `Client-ID ${IMGUR_KEY}` });
if (!body.data.images.length) return null;
this.cache = body.data.images;
this.cache = body.data.images.map(image => image.link);
setTimeout(() => { this.cache = null; }, 3.6e+6);
return body.data.images[Math.floor(Math.random() * body.data.images.length)].link;
}