JaBa/commands/NSFW/nsfw.js

87 lines
2.6 KiB
JavaScript
Raw Normal View History

const { SlashCommandBuilder, ActionRowBuilder, StringSelectMenuBuilder, AttachmentBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand"),
fetch = require("node-fetch");
class NSFW extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
2023-03-27 23:56:20 +05:00
.setName("nsfw")
.setDescription(client.translate("nsfw/nsfw:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("nsfw/nsfw:DESCRIPTION", null, "uk-UA"),
ru: client.translate("nsfw/nsfw:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(true),
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
*/
async onLoad(client) {
client.on("interactionCreate", async interaction => {
if (!interaction.isStringSelectMenu()) return;
if (interaction.customId === "nsfw_select") {
await interaction.deferUpdate();
2024-02-09 23:26:57 +05:00
interaction.data = [];
interaction.data.guild = await client.findOrCreateGuild(interaction.guildId);
const tag = interaction?.values[0],
splitted = tag.split("_"),
res = await fetch(`https://nsfw-api-p302.onrender.com/media/${splitted[0].charAt(0).toLowerCase()}/${splitted[1].toLowerCase()}`).then(async r => await r.buffer()),
image = new AttachmentBuilder(res, { name: "image.jpeg" });
const embed = client.embed({
image: "attachment://image.jpeg",
});
await interaction.editReply({
embeds: [embed],
files: [image],
});
}
});
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
async execute(client, interaction) {
await interaction.deferReply({ ephemeral: true });
2024-02-09 23:26:57 +05:00
if (interaction.guild && !interaction.channel.nsfw) return interaction.error("misc:NSFW_COMMAND", null, { edit: true, ephemeral: true });
const tags = ["Hentai_Vanila", "Hentai_Yaoi", "Hentai_Yuri", "Hentai_BDSM", "Hentai_Trap", "Real_Ass", "Real_Boobs", "Real_Pussy"]
.map(tag =>
JSON.parse(
JSON.stringify({
label: `(${tag.split("_")[0]}) ${tag.split("_")[1]}`,
value: tag,
}),
),
);
const row = new ActionRowBuilder().addComponents(new StringSelectMenuBuilder().setCustomId("nsfw_select").setPlaceholder(interaction.translate("common:NOTHING_SELECTED")).addOptions(tags.slice(0, 25)));
await interaction.editReply({
2022-10-11 15:19:22 +05:00
content: interaction.translate("common:AVAILABLE_OPTIONS"),
ephemeral: true,
components: [row],
2022-10-11 15:19:22 +05:00
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = NSFW;