diff --git a/commands/random/fidget.js b/commands/random/fidget.js index 55b71be1..9de3497c 100644 --- a/commands/random/fidget.js +++ b/commands/random/fidget.js @@ -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?'; } }; diff --git a/commands/random/meme.js b/commands/random/meme.js index f34ccbdc..a186ccce 100644 --- a/commands/random/meme.js +++ b/commands/random/meme.js @@ -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; } }; diff --git a/commands/random/xiao.js b/commands/random/xiao.js index 143d2607..d022a36d 100644 --- a/commands/random/xiao.js +++ b/commands/random/xiao.js @@ -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?'; } }; diff --git a/commands/roleplay/blush.js b/commands/roleplay/blush.js index 61dd839a..c9d7ca71 100644 --- a/commands/roleplay/blush.js +++ b/commands/roleplay/blush.js @@ -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', diff --git a/commands/roleplay/eat.js b/commands/roleplay/eat.js index d4ddc735..b02febe4 100644 --- a/commands/roleplay/eat.js +++ b/commands/roleplay/eat.js @@ -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', diff --git a/commands/roleplay/fist-bump.js b/commands/roleplay/fist-bump.js index 4bec13fc..4f327949 100644 --- a/commands/roleplay/fist-bump.js +++ b/commands/roleplay/fist-bump.js @@ -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', diff --git a/commands/roleplay/high-five.js b/commands/roleplay/high-five.js index 8bf33f1f..62406fa7 100644 --- a/commands/roleplay/high-five.js +++ b/commands/roleplay/high-five.js @@ -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', diff --git a/commands/roleplay/hold-hands.js b/commands/roleplay/hold-hands.js index 55d4e59a..b0fb77f9 100644 --- a/commands/roleplay/hold-hands.js +++ b/commands/roleplay/hold-hands.js @@ -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', diff --git a/commands/roleplay/hug.js b/commands/roleplay/hug.js index 1b89ad6f..82b8250c 100644 --- a/commands/roleplay/hug.js +++ b/commands/roleplay/hug.js @@ -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', diff --git a/commands/roleplay/kill.js b/commands/roleplay/kill.js index 1d6d2901..30431fff 100644 --- a/commands/roleplay/kill.js +++ b/commands/roleplay/kill.js @@ -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', diff --git a/commands/roleplay/kiss.js b/commands/roleplay/kiss.js index f6858a15..1f02acb2 100644 --- a/commands/roleplay/kiss.js +++ b/commands/roleplay/kiss.js @@ -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', diff --git a/commands/roleplay/pat.js b/commands/roleplay/pat.js index 554d8a8a..af529403 100644 --- a/commands/roleplay/pat.js +++ b/commands/roleplay/pat.js @@ -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', diff --git a/commands/roleplay/poke.js b/commands/roleplay/poke.js index 70605ea8..ac0baf43 100644 --- a/commands/roleplay/poke.js +++ b/commands/roleplay/poke.js @@ -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', diff --git a/commands/roleplay/punch.js b/commands/roleplay/punch.js index 1c3e74e2..51ea92ca 100644 --- a/commands/roleplay/punch.js +++ b/commands/roleplay/punch.js @@ -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', diff --git a/commands/roleplay/slap.js b/commands/roleplay/slap.js index 94d93d19..83a954e4 100644 --- a/commands/roleplay/slap.js +++ b/commands/roleplay/slap.js @@ -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', diff --git a/commands/roleplay/sleep.js b/commands/roleplay/sleep.js index 68d97059..b8b2d2c7 100644 --- a/commands/roleplay/sleep.js +++ b/commands/roleplay/sleep.js @@ -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', diff --git a/commands/roleplay/wake-up.js b/commands/roleplay/wake-up.js index b7855478..f37acbf4 100644 --- a/commands/roleplay/wake-up.js +++ b/commands/roleplay/wake-up.js @@ -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', diff --git a/commands/roleplay/wave.js b/commands/roleplay/wave.js index 593138dc..97101099 100644 --- a/commands/roleplay/wave.js +++ b/commands/roleplay/wave.js @@ -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', diff --git a/commands/roleplay/wink.js b/commands/roleplay/wink.js index a9812323..4165fe63 100644 --- a/commands/roleplay/wink.js +++ b/commands/roleplay/wink.js @@ -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', diff --git a/structures/commands/Roleplay.js b/structures/commands/ImgurAlbum.js similarity index 87% rename from structures/commands/Roleplay.js rename to structures/commands/ImgurAlbum.js index 5585ee45..6e7e4d94 100644 --- a/structures/commands/Roleplay.js +++ b/structures/commands/ImgurAlbum.js @@ -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; }