add plugin fun and module meme

This commit is contained in:
Axel Olausson Holtenäs 2022-04-22 16:13:05 +02:00
parent 7837a24a57
commit b924ab9f3d
No known key found for this signature in database
GPG key ID: 7BF6826B76382CBA
4 changed files with 66 additions and 1 deletions

View file

@ -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",

25
src/plugins/fun/index.ts Normal file
View file

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

View file

@ -0,0 +1,5 @@
import meme from "@plugins/fun/modules/meme";
export default {
meme,
};

View file

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