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}`); + }); + }, +};