From a4518c05cebc5c7acb86013d06116aa8ada800fb Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 28 Aug 2018 22:26:58 +0000 Subject: [PATCH] Refactor roleplay commands, bro-hoof, meme, remove face, add dotenv support --- .env.example | 68 +++++++++++++++++++ README.md | 6 +- Xiao.js | 1 + commands/analyze/face.js | 43 ------------ commands/analyze/what-anime.js | 2 +- .../image-edit/{meme.js => create-meme.js} | 7 +- commands/random/fidget.js | 19 +++++- commands/random/meme.js | 38 +++++++++++ commands/random/pikachu.js | 24 ------- commands/random/xiao.js | 19 +++++- commands/roleplay/break-up.js | 17 ++--- commands/roleplay/bro-hoof.js | 26 +++++++ commands/roleplay/cuddle.js | 17 ++--- commands/roleplay/eat.js | 17 ++--- commands/roleplay/evolve.js | 17 ++--- commands/roleplay/falcon-punch.js | 17 ++--- commands/roleplay/fist-bump.js | 19 +++--- commands/roleplay/high-five.js | 17 ++--- commands/roleplay/hit-with-shovel.js | 17 ++--- commands/roleplay/hold-hands.js | 17 ++--- commands/roleplay/hug.js | 17 ++--- commands/roleplay/inhale.js | 20 ++---- commands/roleplay/kill.js | 17 ++--- commands/roleplay/kiss.js | 17 ++--- commands/roleplay/marry.js | 17 ++--- commands/roleplay/pat.js | 17 ++--- commands/roleplay/poke.js | 17 ++--- commands/roleplay/punch.js | 17 ++--- commands/roleplay/slap.js | 17 ++--- commands/roleplay/tackle.js | 17 ++--- commands/search/league-of-legends-champion.js | 2 +- commands/single/eat-pant.js | 2 +- package.json | 3 +- structures/commands/Roleplay.js | 33 +++++++++ util/Util.js | 15 +--- 35 files changed, 349 insertions(+), 287 deletions(-) create mode 100644 .env.example delete mode 100644 commands/analyze/face.js rename commands/image-edit/{meme.js => create-meme.js} (89%) create mode 100644 commands/random/meme.js delete mode 100644 commands/random/pikachu.js create mode 100644 commands/roleplay/bro-hoof.js create mode 100644 structures/commands/Roleplay.js diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..90512032 --- /dev/null +++ b/.env.example @@ -0,0 +1,68 @@ +# Discord-related info +XIAO_TOKEN= +# Seperate OWNERS with a , +OWNERS= +XIAO_PREFIX= +INVITE= + +# Emoji IDs +GOLD_FISH_EMOJI_ID= +MOCKING_EMOJI_ID= +SILVER_FISH_EMOJI_ID= +SUCCESS_EMOJI_ID= + +# API Keys, IDs, and Secrets +ALPHA_VANTAGE_KEY= +CUSTOM_SEARCH_ID= +DEVIANTART_ID= +DEVIANTART_SECRET= +FLICKR_KEY= +GIPHY_KEY= +GITHUB_PASSWORD= +GITHUB_USERNAME= +GOOGLE_CALENDAR_ID= +GOOGLE_KEY= +GOV_KEY= +IMGUR_KEY= +OSU_KEY= +PERSONAL_GOOGLE_CALENDAR_ID= +RIOT_KEY= +STACKOVERFLOW_KEY= +TMDB_KEY= +TUMBLR_KEY= +TWITTER_KEY= +TWITTER_SECRET= +WATTPAD_KEY= +WEBHOOK_ID= +WEBHOOK_TOKEN= +WHATANIME_KEY= +WORDNIK_KEY= +XIAO_GITHUB_REPO_NAME= +XIAO_GITHUB_REPO_USERNAME= +YANDEX_KEY= +YODA_KEY= + +# Imgur album IDs +BREAK_UP_ALBUM_ID= +BRO_HOOF_ALBUM_ID= +CUDDLE_ALBUM_ID= +EAT_ALBUM_ID= +EVOLVE_ALBUM_ID= +FALCON_PUNCH_ALBUM_ID= +FIDGET_ALBUM_ID= +FIST_BUMP_ALBUM_ID= +HIGH_FIVE_ALBUM_ID= +HIT_WITH_SHOVEL_ALBUM_ID= +HOLD_HANDS_ALBUM_ID= +HUG_ALBUM_ID= +INHALE_ALBUM_ID= +KILL_ALBUM_ID= +KISS_ALBUM_ID= +MARRY_ALBUM_ID= +PAT_ALBUM_ID= +POKE_ALBUM_ID= +POSTER_ALBUM_ID= +PUNCH_ALBUM_ID= +SLAP_ALBUM_ID= +TACKLE_ALBUM_ID= +XIAO_ALBUM_ID= diff --git a/README.md b/README.md index b60c6a9d..6c332ffd 100644 --- a/README.md +++ b/README.md @@ -63,12 +63,12 @@ on the [home server](https://discord.gg/sbMe32W). * **joke**: Responds with a random joke. * **kiss-marry-kill**: Determines who to kiss, who to marry, and who to kill. * **magic-conch**: Asks your question to the Magic Conch. +* **meme**: Responds with a random meme. * **name**: Responds with a random name, with the gender of your choice. * **number-fact**: Responds with a random fact about a specific number. * **offspring**: Determines if your new child will be a boy or a girl. * **opinion**: Determines the opinion on something. * **oracle-turret**: Responds with a random Oracle Turret quote. -* **pikachu**: Responds with a random image of Pikachu. * **quantum-coin**: Flips a coin that lands on some form of nothing. * **quote**: Responds with a random quote. * **rate**: Rates something. @@ -174,7 +174,6 @@ on the [home server](https://discord.gg/sbMe32W). * **coolness**: Determines a user's coolness. * **dick**: Determines your dick size. -* **face-analyze**: Determines the age, gender, and race of a face. * **gender-analyze**: Determines the gender of a name. * **guess-looks**: Guesses what a user looks like. * **psycho-pass**: Determines your Crime Coefficient. @@ -226,6 +225,7 @@ on the [home server](https://discord.gg/sbMe32W). * **be-like-bill**: Sends a "Be Like Bill" meme with the name of your choice. * **color**: Sends an image of the color you choose. * **contrast**: Draws an image or a user's avatar but with contrast. +* **create-meme**: Sends a meme with the text and background of your choice. * **create-qr-code**: Converts text to a QR Code. * **demotivational-poster**: Draws an image or a user's avatar and the text you specify as a demotivational poster. * **distort**: Draws an image or a user's avatar but distorted. @@ -235,7 +235,6 @@ on the [home server](https://discord.gg/sbMe32W). * **ifunny**: Draws an image with the iFunny logo. * **illegal**: Makes President Trump make your text illegal. * **invert**: Draws an image or a user's avatar but inverted. -* **meme**: Sends a meme with the text and background of your choice. * **minecraft-skin**: Sends the Minecraft skin for a user. * **needs-more-jpeg**: Draws an image or a user's avatar as a low quality JPEG. * **osu-signature**: Creates a card based on an osu! user's stats. @@ -338,6 +337,7 @@ on the [home server](https://discord.gg/sbMe32W). ### Roleplay: * **break-up**: Breaks up with a user. +* **bro-hoof**: Gives a user a bro-hoof. * **cuddle**: Cuddles a user. * **eat**: Eats a user. * **evolve**: Evolves a user. diff --git a/Xiao.js b/Xiao.js index b6b5568a..50003c74 100644 --- a/Xiao.js +++ b/Xiao.js @@ -1,3 +1,4 @@ +require('dotenv').config(); const { XIAO_TOKEN, OWNERS, XIAO_PREFIX, INVITE } = process.env; const path = require('path'); const { CommandoClient } = require('discord.js-commando'); diff --git a/commands/analyze/face.js b/commands/analyze/face.js deleted file mode 100644 index 98ca2538..00000000 --- a/commands/analyze/face.js +++ /dev/null @@ -1,43 +0,0 @@ -const Command = require('../../structures/Command'); -const request = require('node-superfetch'); -const { KAIROS_KEY, KAIROS_ID } = process.env; -const races = ['asian', 'black', 'hispanic', 'other', 'white']; - -module.exports = class FaceAnalyzeCommand extends Command { - constructor(client) { - super(client, { - name: 'face-analyze', - aliases: ['analyze-face', 'face'], - group: 'analyze', - memberName: 'face', - description: 'Determines the age, gender, and race of a face.', - args: [ - { - key: 'face', - prompt: 'What face do you want to scan?', - type: 'image' - } - ] - }); - } - - async run(msg, { face }) { - try { - const { body } = await request - .post('https://api.kairos.com/detect') - .set({ - app_id: KAIROS_ID, - app_key: KAIROS_KEY - }) - .send({ image: face }); - if (!body.images) return msg.reply('There are no faces in this image.'); - if (body.images[0].faces.length > 1) return msg.reply('Please provide only one face in the image.'); - const data = body.images[0].faces[0].attributes; - const race = races.sort((a, b) => data[b] - data[a])[0]; - const gender = data.gender.maleConfidence > data.gender.femaleConfidence ? 'man' : 'woman'; - return msg.reply(`I think this is a photo of a ${data.age} year old ${race} ${gender}.`); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/commands/analyze/what-anime.js b/commands/analyze/what-anime.js index 35031d76..14895541 100644 --- a/commands/analyze/what-anime.js +++ b/commands/analyze/what-anime.js @@ -50,7 +50,7 @@ module.exports = class WhatAnimeCommand extends Command { .query({ token: WHATANIME_KEY }); return { status: body.quota > 0, refresh: body.quota_ttl }; } catch (err) { - return { status: false, refresh: null }; + return { status: false, refresh: Infinity }; } } diff --git a/commands/image-edit/meme.js b/commands/image-edit/create-meme.js similarity index 89% rename from commands/image-edit/meme.js rename to commands/image-edit/create-meme.js index 566d83e1..a080ff37 100644 --- a/commands/image-edit/meme.js +++ b/commands/image-edit/create-meme.js @@ -1,12 +1,13 @@ const Command = require('../../structures/Command'); const request = require('node-superfetch'); -module.exports = class MemeCommand extends Command { +module.exports = class CreateMemeCommand extends Command { constructor(client) { super(client, { - name: 'meme', + name: 'create-meme', + aliases: ['meme-generator', 'meme-gen'], group: 'image-edit', - memberName: 'meme', + memberName: 'create-meme', description: 'Sends a meme with the text and background of your choice.', clientPermissions: ['ATTACH_FILES'], args: [ diff --git a/commands/random/fidget.js b/commands/random/fidget.js index 23edfc91..55b71be1 100644 --- a/commands/random/fidget.js +++ b/commands/random/fidget.js @@ -1,5 +1,6 @@ const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const request = require('node-superfetch'); +const { IMGUR_KEY, FIDGET_ALBUM_ID } = process.env; module.exports = class FidgetCommand extends Command { constructor(client) { @@ -11,14 +12,28 @@ module.exports = class FidgetCommand extends Command { description: 'Responds with a random image of Fidget.', clientPermissions: ['ATTACH_FILES'] }); + + this.cache = null; } async run(msg) { try { - const nimbat = await randomFromImgurAlbum('DuO1T'); + 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; + } }; diff --git a/commands/random/meme.js b/commands/random/meme.js new file mode 100644 index 00000000..f34ccbdc --- /dev/null +++ b/commands/random/meme.js @@ -0,0 +1,38 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { IMGUR_KEY, POSTER_ALBUM_ID } = process.env; + +module.exports = class MemeCommand extends Command { + constructor(client) { + super(client, { + name: 'meme', + group: 'random', + memberName: 'meme', + description: 'Responds with a random meme.', + clientPermissions: ['ATTACH_FILES'] + }); + + 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; + } +}; diff --git a/commands/random/pikachu.js b/commands/random/pikachu.js deleted file mode 100644 index 1cfd3465..00000000 --- a/commands/random/pikachu.js +++ /dev/null @@ -1,24 +0,0 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); - -module.exports = class PikachuCommand extends Command { - constructor(client) { - super(client, { - name: 'pikachu', - aliases: ['pika'], - group: 'random', - memberName: 'pikachu', - description: 'Responds with a random image of Pikachu.', - clientPermissions: ['ATTACH_FILES'] - }); - } - - async run(msg) { - try { - const pikachu = await randomFromImgurAlbum('qtk2J'); - return msg.say({ files: [pikachu] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/commands/random/xiao.js b/commands/random/xiao.js index b3565da7..143d2607 100644 --- a/commands/random/xiao.js +++ b/commands/random/xiao.js @@ -1,5 +1,6 @@ const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const request = require('node-superfetch'); +const { IMGUR_KEY, XIAO_ALBUM_ID } = process.env; module.exports = class XiaoCommand extends Command { constructor(client) { @@ -11,14 +12,28 @@ module.exports = class XiaoCommand extends Command { description: 'Responds with a random image of Xiao Pai.', clientPermissions: ['ATTACH_FILES'] }); + + this.cache = null; } async run(msg) { try { - const xiao = await randomFromImgurAlbum('S4e3r'); + 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; + } }; diff --git a/commands/roleplay/break-up.js b/commands/roleplay/break-up.js index cfdeeeaf..385c70ca 100644 --- a/commands/roleplay/break-up.js +++ b/commands/roleplay/break-up.js @@ -1,7 +1,7 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { BREAK_UP_ALBUM_ID } = process.env; -module.exports = class BreakUpCommand extends Command { +module.exports = class BreakUpCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'break-up', @@ -9,6 +9,8 @@ module.exports = class BreakUpCommand extends Command { group: 'roleplay', memberName: 'break-up', description: 'Breaks up with a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: BREAK_UP_ALBUM_ID, args: [ { key: 'user', @@ -19,12 +21,7 @@ module.exports = class BreakUpCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('QFWUb'); - return msg.say(`_**${msg.author.username}** breaks up with **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** breaks up with **${user.username}**._`; } }; diff --git a/commands/roleplay/bro-hoof.js b/commands/roleplay/bro-hoof.js new file mode 100644 index 00000000..c7494ab1 --- /dev/null +++ b/commands/roleplay/bro-hoof.js @@ -0,0 +1,26 @@ +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { BRO_HOOF_ALBUM_ID } = process.env; + +module.exports = class BroHoofCommand extends RoleplayCommand { + constructor(client) { + super(client, { + name: 'bro-hoof', + group: 'roleplay', + memberName: 'bro-hoof', + description: 'Gives a user a bro-hoof.', + clientPermissions: ['ATTACH_FILES'], + albumID: BRO_HOOF_ALBUM_ID, + args: [ + { + key: 'user', + prompt: 'What user do you want to roleplay with?', + type: 'user' + } + ] + }); + } + + generateText(msg, user) { + return `_**${msg.author.username}** gives **${user.username}** a bro-hoof._`; + } +}; diff --git a/commands/roleplay/cuddle.js b/commands/roleplay/cuddle.js index dcc4e0af..e946ba36 100644 --- a/commands/roleplay/cuddle.js +++ b/commands/roleplay/cuddle.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { CUDDLE_ALBUM_ID } = process.env; -module.exports = class CuddleCommand extends Command { +module.exports = class CuddleCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'cuddle', group: 'roleplay', memberName: 'cuddle', description: 'Cuddles a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: CUDDLE_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class CuddleCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('sVjXp'); - return msg.say(`_**${msg.author.username}** cuddles with **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** cuddles with **${user.username}**._`; } }; diff --git a/commands/roleplay/eat.js b/commands/roleplay/eat.js index 81dfb6f9..e20e1b66 100644 --- a/commands/roleplay/eat.js +++ b/commands/roleplay/eat.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { EAT_ALBUM_ID } = process.env; -module.exports = class EatCommand extends Command { +module.exports = class EatCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'eat', group: 'roleplay', memberName: 'eat', description: 'Eats a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: EAT_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class EatCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('GP2zD'); - return msg.say(`_**${msg.author.username}** eats **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** eats **${user.username}**._`; } }; diff --git a/commands/roleplay/evolve.js b/commands/roleplay/evolve.js index 70547980..3c2d2693 100644 --- a/commands/roleplay/evolve.js +++ b/commands/roleplay/evolve.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { EVOLVE_ALBUM_ID } = process.env; -module.exports = class EvolveCommand extends Command { +module.exports = class EvolveCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'evolve', group: 'roleplay', memberName: 'evolve', description: 'Evolves a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: EVOLVE_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class EvolveCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('QaDeO'); - return msg.say(`_**${user.username}** is evolving!_`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${user.username}** is evolving!_`; } }; diff --git a/commands/roleplay/falcon-punch.js b/commands/roleplay/falcon-punch.js index 67960d4b..bbc2b3ac 100644 --- a/commands/roleplay/falcon-punch.js +++ b/commands/roleplay/falcon-punch.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { FALCON_PUNCH_ALBUM_ID } = process.env; -module.exports = class FalconPunchCommand extends Command { +module.exports = class FalconPunchCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'falcon-punch', group: 'roleplay', memberName: 'falcon-punch', description: 'Falcon Punches a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: FALCON_PUNCH_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class FalconPunchCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('mJauN'); - return msg.say(`_**${msg.author.username}** falcon punches **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** falcon punches **${user.username}**._`; } }; diff --git a/commands/roleplay/fist-bump.js b/commands/roleplay/fist-bump.js index ac6ed3c9..519d6929 100644 --- a/commands/roleplay/fist-bump.js +++ b/commands/roleplay/fist-bump.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { FIST_BUMP_ALBUM_ID } = process.env; -module.exports = class FistBumpCommand extends Command { +module.exports = class FistBumpCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'fist-bump', group: 'roleplay', memberName: 'fist-bump', - description: 'Fistbumps a user.', + description: 'Fist-bumps a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: FIST_BUMP_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class FistBumpCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('9D3WE'); - return msg.say(`_**${msg.author.username}** fist-bumps **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** fist-bumps **${user.username}**._`; } }; diff --git a/commands/roleplay/high-five.js b/commands/roleplay/high-five.js index 997e3e89..8bf33f1f 100644 --- a/commands/roleplay/high-five.js +++ b/commands/roleplay/high-five.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { HIGH_FIVE_ALBUM_ID } = process.env; -module.exports = class HighFiveCommand extends Command { +module.exports = class HighFiveCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'high-five', group: 'roleplay', memberName: 'high-five', description: 'High Fives a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: HIGH_FIVE_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class HighFiveCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('1Dotc'); - return msg.say(`_**${msg.author.username}** high-fives **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** high-fives **${user.username}**._`; } }; diff --git a/commands/roleplay/hit-with-shovel.js b/commands/roleplay/hit-with-shovel.js index c217da0f..54760945 100644 --- a/commands/roleplay/hit-with-shovel.js +++ b/commands/roleplay/hit-with-shovel.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { HIT_WITH_SHOVEL_ALBUM_ID } = process.env; -module.exports = class HitWithShovelCommand extends Command { +module.exports = class HitWithShovelCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'hit-with-shovel', group: 'roleplay', memberName: 'hit-with-shovel', description: 'Hits a user with a shovel.', + clientPermissions: ['ATTACH_FILES'], + albumID: HIT_WITH_SHOVEL_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class HitWithShovelCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('IA35f'); - return msg.say(`_**${msg.author.username}** hits **${user.username}** with a shovel._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** hits **${user.username}** with a shovel._`; } }; diff --git a/commands/roleplay/hold-hands.js b/commands/roleplay/hold-hands.js index 8d449889..55d4e59a 100644 --- a/commands/roleplay/hold-hands.js +++ b/commands/roleplay/hold-hands.js @@ -1,7 +1,7 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { HOLD_HANDS_ALBUM_ID } = process.env; -module.exports = class HoldHandsCommand extends Command { +module.exports = class HoldHandsCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'hold-hands', @@ -9,6 +9,8 @@ module.exports = class HoldHandsCommand extends Command { group: 'roleplay', memberName: 'hold-hands', description: 'Holds hands with a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: HOLD_HANDS_ALBUM_ID, args: [ { key: 'user', @@ -19,12 +21,7 @@ module.exports = class HoldHandsCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('K67Lp'); - return msg.say(`_**${msg.author.username}** holds **${user.username}**'s hand._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** holds **${user.username}**'s hand._`; } }; diff --git a/commands/roleplay/hug.js b/commands/roleplay/hug.js index 260f9887..9315a7c0 100644 --- a/commands/roleplay/hug.js +++ b/commands/roleplay/hug.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { HUG_ALBUM_ID } = process.env; -module.exports = class HugCommand extends Command { +module.exports = class HugCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'hug', group: 'roleplay', memberName: 'hug', description: 'Hugs a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: HUG_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class HugCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('v4Sdd'); - return msg.say(`_**${msg.author.username}** hugs **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** hugs **${user.username}**._`; } }; diff --git a/commands/roleplay/inhale.js b/commands/roleplay/inhale.js index 3cdc31d6..6e904a34 100644 --- a/commands/roleplay/inhale.js +++ b/commands/roleplay/inhale.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { INHALE_ALBUM_ID } = process.env; -module.exports = class InhaleCommand extends Command { +module.exports = class InhaleCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'inhale', group: 'roleplay', memberName: 'inhale', description: 'Inhales a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: INHALE_ALBUM_ID, args: [ { key: 'user', @@ -18,15 +20,7 @@ module.exports = class InhaleCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('QKFM6'); - return msg.say( - `_**${msg.author.username}** inhales **${user.username}** but gained no ability..._`, - { files: [gif] } - ); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** inhales **${user.username}** but gained no ability..._`; } }; diff --git a/commands/roleplay/kill.js b/commands/roleplay/kill.js index e0c7e105..1d6d2901 100644 --- a/commands/roleplay/kill.js +++ b/commands/roleplay/kill.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { KILL_ALBUM_ID } = process.env; -module.exports = class KillCommand extends Command { +module.exports = class KillCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'kill', group: 'roleplay', memberName: 'kill', description: 'Kills a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: KILL_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class KillCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('YhwEI'); - return msg.say(`_**${msg.author.username}** kills **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** kills **${user.username}**._`; } }; diff --git a/commands/roleplay/kiss.js b/commands/roleplay/kiss.js index fc0fe16c..9a6b92f1 100644 --- a/commands/roleplay/kiss.js +++ b/commands/roleplay/kiss.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { KISS_ALBUM_ID } = process.env; -module.exports = class KissCommand extends Command { +module.exports = class KissCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'kiss', group: 'roleplay', memberName: 'kiss', description: 'Kisses a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: KISS_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class KissCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('twIbD'); - return msg.say(`_**${msg.author.username}** kisses **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** kisses **${user.username}**._`; } }; diff --git a/commands/roleplay/marry.js b/commands/roleplay/marry.js index d1205463..5eafb5e2 100644 --- a/commands/roleplay/marry.js +++ b/commands/roleplay/marry.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { MARRY_ALBUM_ID } = process.env; -module.exports = class MarryCommand extends Command { +module.exports = class MarryCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'marry', group: 'roleplay', memberName: 'marry', description: 'Marries a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: MARRY_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class MarryCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('4H0EP'); - return msg.say(`_**${msg.author.username}** marries **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** marries **${user.username}**._`; } }; diff --git a/commands/roleplay/pat.js b/commands/roleplay/pat.js index 5c2a6c13..554d8a8a 100644 --- a/commands/roleplay/pat.js +++ b/commands/roleplay/pat.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { PAT_ALBUM_ID } = process.env; -module.exports = class PatCommand extends Command { +module.exports = class PatCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'pat', group: 'roleplay', memberName: 'pat', description: 'Pats a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: PAT_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class PatCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('JPwZG'); - return msg.say(`_**${msg.author.username}** pats **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** pats **${user.username}**._`; } }; diff --git a/commands/roleplay/poke.js b/commands/roleplay/poke.js index 0ca77d69..70605ea8 100644 --- a/commands/roleplay/poke.js +++ b/commands/roleplay/poke.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { POKE_ALBUM_ID } = process.env; -module.exports = class PokeCommand extends Command { +module.exports = class PokeCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'poke', group: 'roleplay', memberName: 'poke', description: 'Pokes a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: POKE_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class PokeCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('ek91V'); - return msg.say(`_**${msg.author.username}** pokes **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** pokes **${user.username}**._`; } }; diff --git a/commands/roleplay/punch.js b/commands/roleplay/punch.js index 7ba2ff2a..fbacdf59 100644 --- a/commands/roleplay/punch.js +++ b/commands/roleplay/punch.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { PUNCH_ALBUM_ID } = process.env; -module.exports = class PunchCommand extends Command { +module.exports = class PunchCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'punch', group: 'roleplay', memberName: 'punch', description: 'Punches a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: PUNCH_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class PunchCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('mZrp8'); - return msg.say(`_**${msg.author.username}** punches **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** punches **${user.username}**._`; } }; diff --git a/commands/roleplay/slap.js b/commands/roleplay/slap.js index f17dd7d7..29e9ca29 100644 --- a/commands/roleplay/slap.js +++ b/commands/roleplay/slap.js @@ -1,13 +1,15 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { PUNCH_ALBUM_ID } = process.env; -module.exports = class SlapCommand extends Command { +module.exports = class SlapCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'slap', group: 'roleplay', memberName: 'slap', description: 'Slaps a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: PUNCH_ALBUM_ID, args: [ { key: 'user', @@ -18,12 +20,7 @@ module.exports = class SlapCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('6wu9G'); - return msg.say(`_**${msg.author.username}** slaps **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** slaps **${user.username}**._`; } }; diff --git a/commands/roleplay/tackle.js b/commands/roleplay/tackle.js index 25d565ab..37b9d8ed 100644 --- a/commands/roleplay/tackle.js +++ b/commands/roleplay/tackle.js @@ -1,7 +1,7 @@ -const Command = require('../../structures/Command'); -const { randomFromImgurAlbum } = require('../../util/Util'); +const RoleplayCommand = require('../../structures/commands/Roleplay'); +const { TACKLE_ALBUM_ID } = process.env; -module.exports = class TackleCommand extends Command { +module.exports = class TackleCommand extends RoleplayCommand { constructor(client) { super(client, { name: 'tackle', @@ -9,6 +9,8 @@ module.exports = class TackleCommand extends Command { group: 'roleplay', memberName: 'tackle', description: 'Tackles a user.', + clientPermissions: ['ATTACH_FILES'], + albumID: TACKLE_ALBUM_ID, args: [ { key: 'user', @@ -19,12 +21,7 @@ module.exports = class TackleCommand extends Command { }); } - async run(msg, { user }) { - try { - const gif = await randomFromImgurAlbum('SZGLX'); - return msg.say(`_**${msg.author.username}** tackles **${user.username}**._`, { files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } + generateText(msg, user) { + return `_**${msg.author.username}** tackles **${user.username}**._`; } }; diff --git a/commands/search/league-of-legends-champion.js b/commands/search/league-of-legends-champion.js index acd8c10c..5d7cb5e4 100644 --- a/commands/search/league-of-legends-champion.js +++ b/commands/search/league-of-legends-champion.js @@ -70,7 +70,7 @@ module.exports = class LeagueOfLegendsChampionCommand extends Command { .get('https://na1.api.riotgames.com/lol/static-data/v3/versions') .query({ api_key: RIOT_KEY }); [this.version] = body; - setTimeout(() => { this.version = null; }, 3600000); + setTimeout(() => { this.version = null; }, 3.6e+6); return body; } diff --git a/commands/single/eat-pant.js b/commands/single/eat-pant.js index c82b14fd..f072da30 100644 --- a/commands/single/eat-pant.js +++ b/commands/single/eat-pant.js @@ -12,6 +12,6 @@ module.exports = class EatPantCommand extends Command { } run(msg) { - return msg.say({ files: ['https://i.imgur.com/sSmhvxt.jpg'] }); + return msg.say({ files: ['https://i.imgur.com/uEk0kI4.jpg'] }); } }; diff --git a/package.json b/package.json index 045d9055..f4f97d89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "87.5.1", + "version": "88.0.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { @@ -39,6 +39,7 @@ "custom-translate": "^2.2.6", "discord.js": "github:discordjs/discord.js", "discord.js-commando": "github:discordjs/Commando", + "dotenv": "^6.0.0", "erlpack": "github:discordapp/erlpack", "mathjs": "^5.1.1", "neopet-image-finder": "^4.0.0", diff --git a/structures/commands/Roleplay.js b/structures/commands/Roleplay.js new file mode 100644 index 00000000..5585ee45 --- /dev/null +++ b/structures/commands/Roleplay.js @@ -0,0 +1,33 @@ +const request = require('node-superfetch'); +const Command = require('../Command'); +const { IMGUR_KEY } = process.env; + +module.exports = class RoleplayCommand extends Command { + constructor(client, info) { + super(client, info); + + this.albumID = info.albumID; + this.cache = null; + } + + async run(msg, { user }) { + try { + const image = await this.random(); + if (!image) return msg.reply('This album has no images...'); + return msg.say(this.generateText(msg, user), { files: [image] }); + } 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/${this.albumID}`) + .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; + } +}; diff --git a/util/Util.js b/util/Util.js index 79d9abcf..0ea2ec2d 100644 --- a/util/Util.js +++ b/util/Util.js @@ -1,8 +1,7 @@ -const request = require('node-superfetch'); const crypto = require('crypto'); -const { IMGUR_KEY, SUCCESS_EMOJI_ID } = process.env; -const yes = ['yes', 'y', 'ye', 'yeah', 'yup', 'yea']; -const no = ['no', 'n', 'nah', 'nope']; +const { SUCCESS_EMOJI_ID } = process.env; +const yes = ['yes', 'y', 'ye', 'yeah', 'yup', 'yea', 'ya']; +const no = ['no', 'n', 'nah', 'nope', 'nop']; module.exports = class Util { static delay(ms) { @@ -59,14 +58,6 @@ module.exports = class Util { return crypto.createHash(algorithm).update(text).digest('hex'); } - static async randomFromImgurAlbum(album) { - const { body } = await request - .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 today(timeZone) { const now = new Date(); if (timeZone) now.setUTCHours(now.getUTCHours() + timeZone);