From b924ab9f3d3a0791387aa2364e02654b4de61e79 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 22 Apr 2022 16:13:05 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20plugin=20fun=20and=20module?= =?UTF-8?q?=20meme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/plugins/fun/index.ts | 25 +++++++++++++++++++++++ src/plugins/fun/modules/index.ts | 5 +++++ src/plugins/fun/modules/meme.ts | 35 ++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/plugins/fun/index.ts create mode 100644 src/plugins/fun/modules/index.ts create mode 100644 src/plugins/fun/modules/meme.ts diff --git a/package.json b/package.json index 240f783..7dcc8e3 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@crowdin/ota-client": "^0.7.0", "@discordjs/builders": "^0.13.0", "@discordjs/rest": "^0.4.0", - "axios": "^0.26.0", + "axios": "^0.26.1", "chance": "^1.1.8", "common": "^0.2.5", "crypto": "^1.0.1", diff --git a/src/plugins/fun/index.ts b/src/plugins/fun/index.ts new file mode 100644 index 0000000..06a9e0b --- /dev/null +++ b/src/plugins/fun/index.ts @@ -0,0 +1,25 @@ +import { SlashCommandBuilder } from "@discordjs/builders"; +import { CommandInteraction } from "discord.js"; +import logger from "@logger"; + +import modules from "@plugins/fun/modules"; + +export default { + data: new SlashCommandBuilder() + .setName("fun") + .setDescription("Fun commands.") + + .addSubcommand(modules.meme.data), + + async execute(interaction: CommandInteraction) { + const { options } = interaction; + + switch (options.getSubcommand()) { + case "meme": + await modules.meme.execute(interaction); + break; + default: + logger.verbose(`Unknown subcommand ${options.getSubcommand()}`); + } + }, +}; diff --git a/src/plugins/fun/modules/index.ts b/src/plugins/fun/modules/index.ts new file mode 100644 index 0000000..2b59097 --- /dev/null +++ b/src/plugins/fun/modules/index.ts @@ -0,0 +1,5 @@ +import meme from "@plugins/fun/modules/meme"; + +export default { + meme, +}; diff --git a/src/plugins/fun/modules/meme.ts b/src/plugins/fun/modules/meme.ts new file mode 100644 index 0000000..c263fe6 --- /dev/null +++ b/src/plugins/fun/modules/meme.ts @@ -0,0 +1,35 @@ +import { successColor, footerText, footerIcon } from "@config/embed"; + +import axios from "axios"; +import { CommandInteraction, MessageEmbed } from "discord.js"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import logger from "@logger"; + +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command.setName("meme").setDescription("Get a meme from r/memes)"); + }, + execute: async (interaction: CommandInteraction) => { + await axios + .get("https://www.reddit.com/r/memes/random/.json") + .then(async (res) => { + const response = res.data[0].data.children; + const content = response[0].data; + + const embed = new MessageEmbed() + .setTitle(content.title) + .setTimestamp(new Date()) + .setImage(content.url) + .setFooter({ + text: `👍 ${content.ups}︱👎 ${content.downs}\n${footerText}`, + iconURL: footerIcon, + }) + .setColor(successColor); + + return interaction.editReply({ embeds: [embed] }); + }) + .catch((error) => { + logger.error(`${error}`); + }); + }, +};