2024-02-06 21:45:53 +05:00
|
|
|
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionsBitField } = require("discord.js");
|
2022-08-06 20:47:47 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Poll extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-08-06 20:47:47 +05:00
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("poll")
|
|
|
|
.setDescription(client.translate("moderation/poll:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.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"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.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),
|
|
|
|
),
|
2022-08-06 20:47:47 +05:00
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-06 20:47:47 +05:00
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2022-08-06 20:47:47 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-08-06 20:47:47 +05:00
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
2022-08-09 23:48:33 +05:00
|
|
|
* @param {Object} data
|
2022-08-06 20:47:47 +05:00
|
|
|
*/
|
|
|
|
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),
|
|
|
|
);
|
2022-08-06 20:47:47 +05:00
|
|
|
|
|
|
|
await interaction.reply({
|
|
|
|
content: interaction.translate("moderation/poll:SELECT_MENTION"),
|
|
|
|
ephemeral: true,
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [row],
|
2022-08-06 20:47:47 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
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 });
|
2022-08-06 20:47:47 +05:00
|
|
|
|
|
|
|
collector.on("collect", async i => {
|
|
|
|
if (i.isButton()) {
|
|
|
|
if (i.customId === "poll_everyone") {
|
2022-08-09 23:48:33 +05:00
|
|
|
mention = "||@everyone||";
|
2022-08-06 20:47:47 +05:00
|
|
|
i.update({
|
|
|
|
content: interaction.translate("moderation/poll:POLL_SENDED"),
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [],
|
2022-08-06 20:47:47 +05:00
|
|
|
});
|
|
|
|
} else if (i.customId === "poll_here") {
|
2022-08-09 23:48:33 +05:00
|
|
|
mention = "||@here||";
|
2022-08-06 20:47:47 +05:00
|
|
|
i.update({
|
|
|
|
content: interaction.translate("moderation/poll:POLL_SENDED"),
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [],
|
2022-08-06 20:47:47 +05:00
|
|
|
});
|
|
|
|
} else if (i.customId === "poll_nothing") {
|
|
|
|
mention = null;
|
|
|
|
i.update({
|
|
|
|
content: interaction.translate("moderation/poll:POLL_SENDED"),
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [],
|
2022-08-06 20:47:47 +05:00
|
|
|
});
|
|
|
|
} else if (i.customId === "poll_cancel") {
|
|
|
|
return i.update({
|
|
|
|
content: interaction.translate("misc:SELECT_CANCELED"),
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [],
|
2022-08-06 20:47:47 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
2024-02-06 21:45:53 +05:00
|
|
|
const embed = client.embed({
|
|
|
|
author: interaction.translate("moderation/poll:TITLE"),
|
|
|
|
fields: [
|
2022-08-06 20:47:47 +05:00
|
|
|
{
|
2022-08-06 20:59:55 +05:00
|
|
|
name: "\u200b",
|
2022-12-15 21:02:38 +05:00
|
|
|
value: question,
|
2022-08-06 20:59:55 +05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "\u200b",
|
2022-08-06 20:47:47 +05:00
|
|
|
value: interaction.translate("moderation/poll:REACT", {
|
|
|
|
success: cool.toString(),
|
2022-12-15 21:02:38 +05:00
|
|
|
error: notcool.toString(),
|
|
|
|
}),
|
|
|
|
},
|
2024-02-06 21:45:53 +05:00
|
|
|
],
|
|
|
|
});
|
2022-08-06 20:47:47 +05:00
|
|
|
|
|
|
|
return interaction.channel.send({
|
|
|
|
content: mention,
|
2022-12-15 21:02:38 +05:00
|
|
|
embeds: [embed],
|
2022-08-06 20:47:47 +05:00
|
|
|
}).then(async m => {
|
|
|
|
await m.react(cool);
|
|
|
|
await m.react(notcool);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Poll;
|