2022-08-06 20:47:47 +05:00
|
|
|
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionFlagsBits } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Poll extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("poll")
|
|
|
|
.setDescription(client.translate("moderation/poll:DESCRIPTION"))
|
2023-03-26 18:31:19 +05:00
|
|
|
.setDescriptionLocalizations({ "uk": client.translate("moderation/poll:DESCRIPTION", null, "uk-UA") })
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(false)
|
2022-08-06 20:47:47 +05:00
|
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers && PermissionFlagsBits.ManageMessages)
|
|
|
|
.addStringOption(option => option.setName("question")
|
|
|
|
.setDescription(client.translate("moderation/poll:QUESTION"))
|
2023-03-26 18:31:19 +05:00
|
|
|
.setDescriptionLocalizations({ "uk": client.translate("moderation/poll:QUESTION", null, "uk-UA") })
|
2022-08-06 20:47:47 +05:00
|
|
|
.setRequired(true)),
|
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-06 20:47:47 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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
|
2022-08-06 20:47:47 +05:00
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
|
|
|
const question = interaction.options.getString("question");
|
|
|
|
|
|
|
|
const row = new ActionRowBuilder()
|
|
|
|
.addComponents(
|
|
|
|
new ButtonBuilder()
|
|
|
|
.setCustomId("poll_everyone")
|
2022-08-09 23:48:33 +05:00
|
|
|
.setLabel("@everyone")
|
2022-08-06 20:47:47 +05:00
|
|
|
.setStyle(ButtonStyle.Primary),
|
|
|
|
new ButtonBuilder()
|
|
|
|
.setCustomId("poll_here")
|
2022-08-09 23:48:33 +05:00
|
|
|
.setLabel("@here")
|
2022-08-06 20:47:47 +05:00
|
|
|
.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,
|
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;
|
2022-08-28 21:53:54 +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]);
|
|
|
|
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setAuthor({
|
2022-12-15 21:02:38 +05:00
|
|
|
name: interaction.translate("moderation/poll:TITLE"),
|
2022-08-06 20:47:47 +05:00
|
|
|
})
|
|
|
|
.setColor(client.config.embed.color)
|
|
|
|
.addFields([
|
|
|
|
{
|
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(),
|
|
|
|
}),
|
|
|
|
},
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Poll;
|