JaBa/commands/Moderation/poll.js

120 lines
3.7 KiB
JavaScript
Raw Permalink Normal View History

const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionsBitField } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand");
class Poll extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("poll")
.setDescription(client.translate("moderation/poll:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("moderation/poll:DESCRIPTION", null, "uk-UA"),
ru: client.translate("moderation/poll:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(false)
2023-07-03 21:13:08 +05:00
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages)
2023-07-05 00:58:06 +05:00
.addStringOption(option =>
option
.setName("question")
.setDescription(client.translate("moderation/poll:QUESTION"))
.setDescriptionLocalizations({
uk: client.translate("moderation/poll:QUESTION", null, "uk-UA"),
ru: client.translate("moderation/poll:QUESTION", null, "ru-RU"),
})
.setRequired(true),
),
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
async execute(client, interaction) {
const question = interaction.options.getString("question");
2023-07-05 00:58:06 +05:00
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder().setCustomId("poll_everyone").setLabel("@everyone").setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId("poll_here").setLabel("@here").setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId("poll_nothing").setLabel(interaction.translate("moderation/poll:NOTHING")).setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId("poll_cancel").setLabel(interaction.translate("common:CANCEL")).setStyle(ButtonStyle.Danger),
);
await interaction.reply({
content: interaction.translate("moderation/poll:SELECT_MENTION"),
ephemeral: true,
components: [row],
});
let mention = null;
const filter = i => i.user.id === interaction.user.id;
2023-07-05 00:58:06 +05:00
const collector = interaction.channel.createMessageComponentCollector({ filter, idle: 15 * 1000 });
collector.on("collect", async i => {
if (i.isButton()) {
if (i.customId === "poll_everyone") {
2022-08-09 23:48:33 +05:00
mention = "||@everyone||";
i.update({
content: interaction.translate("moderation/poll:POLL_SENDED"),
components: [],
});
} else if (i.customId === "poll_here") {
2022-08-09 23:48:33 +05:00
mention = "||@here||";
i.update({
content: interaction.translate("moderation/poll:POLL_SENDED"),
components: [],
});
} else if (i.customId === "poll_nothing") {
mention = null;
i.update({
content: interaction.translate("moderation/poll:POLL_SENDED"),
components: [],
});
} else if (i.customId === "poll_cancel") {
return i.update({
content: interaction.translate("misc:SELECT_CANCELED"),
components: [],
});
}
const cool = client.emojis.cache.find(e => e.name === client.customEmojis.cool.split(":")[1]);
const notcool = client.emojis.cache.find(e => e.name === client.customEmojis.notcool.split(":")[1]);
const embed = client.embed({
author: interaction.translate("moderation/poll:TITLE"),
fields: [
{
2024-04-07 15:29:16 +05:00
name: "\u200B",
value: question,
},
{
2024-04-07 15:29:16 +05:00
name: "\u200B",
value: interaction.translate("moderation/poll:REACT", {
success: cool.toString(),
error: notcool.toString(),
}),
},
],
});
return interaction.channel.send({
content: mention,
embeds: [embed],
}).then(async m => {
await m.react(cool);
await m.react(notcool);
});
}
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Poll;