JaBa/commands/NSFW/nsfw.js

94 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-10-11 15:09:30 +05:00
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, SelectMenuBuilder, ChannelType } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand"),
fetch = require("node-fetch");
class NSFW extends BaseCommand {
/**
*
* @param {import("../base/JaBa")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("nsfw")
.setDescription(client.translate("nsfw/nsfw:DESCRIPTION")),
aliases: [],
dirname: __dirname,
guildOnly: false,
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({ ephemeral: true });
2022-10-11 15:16:51 +05:00
if (interaction.channel.type === ChannelType.DM || interaction.channel.nsfw) {
const tags = ["hentai", "ecchi", "lewdanimegirls", "hentaifemdom", "animefeets", "animebooty", "biganimetiddies", "sideoppai", "ahegao"].map(tag =>
JSON.parse(JSON.stringify({
label: tag,
value: tag
}))
);
2022-10-11 15:16:51 +05:00
const row = new ActionRowBuilder()
.addComponents(
new SelectMenuBuilder()
.setCustomId("nsfw_select")
.setPlaceholder(client.translate("common:NOTHING_SELECTED"))
.addOptions(tags)
);
2022-10-11 15:16:51 +05:00
await interaction.editReply({
content: interaction.translate("common:AVAILABLE_OPTIONS"),
ephemeral: true,
components: [row]
});
2022-10-11 15:16:51 +05:00
const filter = i => i.user.id === interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter, idle: (2 * 60 * 1000) });
2022-10-11 15:16:51 +05:00
collector.on("collect", async i => {
if (i.isSelectMenu() && i.customId === "nsfw_select") {
i.deferUpdate();
2022-10-11 15:16:51 +05:00
const tag = i?.values[0];
const res = await fetch(`https://meme-api.herokuapp.com/gimme/${tag}`).then(response => response.json());
2022-10-11 15:16:51 +05:00
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();
2022-10-11 15:16:51 +05:00
await interaction.editReply({
embeds: [embed]
});
}
});
2022-10-11 15:16:51 +05:00
collector.on("end", () => {
return interaction.editReply({
components: []
});
});
2022-10-11 15:16:51 +05:00
} else return interaction.replyT("misc:NSFW_COMMAND", null, { ephemeral: true, edit: true });
}
}
module.exports = NSFW;