JaBa/commands/!DISABLED/memes.js

98 lines
2.6 KiB
JavaScript
Raw Normal View History

const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand"),
fetch = require("node-fetch");
class Memes extends BaseCommand {
/**
*
* @param {import("../base/JaBa")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("memes")
.setDescription(client.translate("fun/memes:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("fun/memes:DESCRIPTION", null, "uk-UA"),
ru: client.translate("fun/memes:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(false),
aliases: [],
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
* @param {import("../../base/JaBa")} client
*/
async onLoad() {
//...
}
/**
*
* @param {import("../../base/JaBa")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
2022-08-09 23:48:33 +05:00
* @param {Object} data
*/
async execute(client, interaction) {
await interaction.deferReply();
const tags = ["funny", "memes", "dankmemes", "me_irl", "wholesomememes"].map(tag =>
2023-07-05 00:58:06 +05:00
JSON.parse(
JSON.stringify({
label: tag,
value: tag,
}),
),
);
2023-07-05 00:58:06 +05:00
const row = new ActionRowBuilder().addComponents(
new StringSelectMenuBuilder()
.setCustomId("memes_select")
.setPlaceholder(client.translate("common:NOTHING_SELECTED"))
.addOptions(tags),
);
const msg = await interaction.editReply({
2022-08-08 18:19:56 +05:00
content: interaction.translate("common:AVAILABLE_OPTIONS"),
fetchReply: true,
components: [row],
});
const filter = i => i.user.id === interaction.user.id;
2023-07-05 00:58:06 +05:00
const collector = msg.createMessageComponentCollector({ filter, idle: 2 * 60 * 1000 });
collector.on("collect", async i => {
if (i.isStringSelectMenu() && i.customId === "memes_select") {
i.deferUpdate();
const tag = i.values[0];
const res = await fetch(`https://meme-api.com/gimme/${tag}`).then(response => response.json());
const embed = new EmbedBuilder()
.setColor(client.config.embed.color)
.setFooter({
text: client.config.embed.footer,
})
.setTitle(res.title)
.setDescription(`${interaction.translate("fun/memes:SUBREDDIT")}: **${res.subreddit}**\n${interaction.translate("common:AUTHOR")}: **${res.author}**\n${interaction.translate("fun/memes:UPS")}: **${res.ups}**`)
.setImage(res.url)
.setTimestamp();
await interaction.editReply({
embeds: [embed],
});
}
});
collector.on("end", () => {
return interaction.editReply({
components: [],
});
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Memes;