2022-12-17 13:33:33 +05:00
|
|
|
const { SlashCommandBuilder, PermissionFlagsBits, ActionRowBuilder, StringSelectMenuBuilder } = require("discord.js");
|
2022-11-09 21:33:45 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Selectroles extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("selectroles")
|
|
|
|
.setDescription(client.translate("administration/selectroles:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
|
|
|
"uk": client.translate("administration/selectroles:DESCRIPTION", null, "uk-UA"),
|
|
|
|
"ru": client.translate("administration/selectroles:DESCRIPTION", null, "ru-RU"),
|
|
|
|
})
|
2022-11-09 21:33:45 +05:00
|
|
|
.setDMPermission(false)
|
|
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
|
|
|
|
.addSubcommand(subcommand => subcommand.setName("message")
|
|
|
|
.setDescription(client.translate("administration/selectroles:MESSAGE"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
|
|
|
"uk": client.translate("administration/selectroles:MESSAGE", null, "uk-UA"),
|
|
|
|
"ru": client.translate("administration/selectroles:MESSAGE", null, "ru-RU"),
|
|
|
|
})
|
2022-11-09 21:33:45 +05:00
|
|
|
.addStringOption(option => option.setName("text")
|
|
|
|
.setDescription(client.translate("common:MESSAGE"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
|
|
|
"uk": client.translate("common:MESSAGE", null, "uk-UA"),
|
|
|
|
"ru": client.translate("common:MESSAGE", null, "ru-RU"),
|
|
|
|
})
|
2022-12-15 21:02:38 +05:00
|
|
|
.setRequired(true)),
|
2022-11-09 21:33:45 +05:00
|
|
|
)
|
|
|
|
.addSubcommand(subcommand => subcommand.setName("addrole")
|
|
|
|
.setDescription(client.translate("administration/selectroles:ADDROLE"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
|
|
|
"uk": client.translate("administration/selectroles:ADDROLE", null, "uk-UA"),
|
|
|
|
"ru": client.translate("administration/selectroles:ADDROLE", null, "ru-RU"),
|
|
|
|
})
|
2022-11-09 21:33:45 +05:00
|
|
|
.addChannelOption(option => option.setName("channel")
|
|
|
|
.setDescription(client.translate("common:CHANNEL"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
|
|
|
"uk": client.translate("common:CHANNEL", null, "uk-UA"),
|
|
|
|
"ru": client.translate("common:CHANNEL", null, "ru-RU"),
|
|
|
|
})
|
2022-11-09 21:33:45 +05:00
|
|
|
.setRequired(true))
|
|
|
|
.addStringOption(option => option.setName("message_id")
|
|
|
|
.setDescription(client.translate("common:MESSAGE_ID"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
|
|
|
"uk": client.translate("common:MESSAGE_ID", null, "uk-UA"),
|
|
|
|
"ru": client.translate("common:MESSAGE_ID", null, "ru-RU"),
|
|
|
|
})
|
2022-11-09 21:33:45 +05:00
|
|
|
.setRequired(true))
|
|
|
|
.addRoleOption(option => option.setName("role")
|
|
|
|
.setDescription(client.translate("common:ROLE"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
|
|
|
"uk": client.translate("common:ROLE", null, "uk-UA"),
|
|
|
|
"ru": client.translate("common:ROLE", null, "ru-RU"),
|
|
|
|
})
|
2022-12-15 21:02:38 +05:00
|
|
|
.setRequired(true)),
|
2022-11-09 21:33:45 +05:00
|
|
|
),
|
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-11-09 21:33:45 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
async onLoad(client) {
|
2022-11-18 21:51:05 +05:00
|
|
|
client.on("interactionCreate", async interaction => {
|
2022-12-17 13:33:33 +05:00
|
|
|
if (!interaction.isStringSelectMenu()) return;
|
2022-11-09 21:33:45 +05:00
|
|
|
|
|
|
|
if (interaction.customId === "auto_roles") {
|
|
|
|
const removed = interaction.component.options.filter(option => {
|
|
|
|
return !interaction.values.includes(option.value);
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const id of removed) {
|
2022-11-18 21:51:05 +05:00
|
|
|
await interaction.member.roles.remove(id.value);
|
2022-11-09 21:33:45 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const id of interaction.values) {
|
2022-11-18 21:51:05 +05:00
|
|
|
await interaction.member.roles.add(id);
|
2022-11-09 21:33:45 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
interaction.reply({
|
2022-12-17 13:49:03 +05:00
|
|
|
content: interaction.translate("administration/selectroles:ROLES_UPDATED"),
|
2022-12-15 21:02:38 +05:00
|
|
|
ephemeral: true,
|
2022-11-09 21:33:45 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
|
|
* @param {Object} data
|
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
|
|
|
await interaction.deferReply({ ephemeral: true });
|
|
|
|
|
|
|
|
const command = interaction.options.getSubcommand();
|
|
|
|
|
|
|
|
if (command === "message") {
|
|
|
|
const text = interaction.options.getString("text");
|
|
|
|
|
|
|
|
interaction.channel.send(text).then(message => {
|
|
|
|
interaction.success("administration/selectroles:MESSAGE_SENT", {
|
|
|
|
channel: interaction.channel.toString(),
|
2022-12-15 21:02:38 +05:00
|
|
|
message_id: message.id,
|
2022-11-09 21:33:45 +05:00
|
|
|
}, { edit: true });
|
|
|
|
});
|
|
|
|
} else if (command === "addrole") {
|
2023-01-09 01:39:13 +05:00
|
|
|
const channel = interaction.options.getChannel("channel"),
|
|
|
|
message_id = interaction.options.getString("message_id"),
|
|
|
|
message = await channel.messages.fetch(message_id);
|
|
|
|
|
2022-11-09 21:33:45 +05:00
|
|
|
if (!message || message.author.id !== client.user.id) return interaction.error("administration/selectroles:MESSAGE_ROLE", null, { edit: true });
|
|
|
|
const role = interaction.options.getRole("role");
|
|
|
|
|
|
|
|
let row = message.components[0];
|
|
|
|
if (!row) row = new ActionRowBuilder();
|
|
|
|
|
|
|
|
const option = [{
|
|
|
|
label: role.name,
|
2022-12-15 21:02:38 +05:00
|
|
|
value: role.id,
|
2022-11-09 21:33:45 +05:00
|
|
|
}];
|
|
|
|
|
|
|
|
const menu = row.components[0];
|
|
|
|
if (menu) {
|
|
|
|
for (const o of menu.options) {
|
|
|
|
if (o.value === option[0].value) return interaction.error("administration/selectroles:ALREADY_IN_MENU");
|
|
|
|
}
|
|
|
|
|
|
|
|
row = ActionRowBuilder.from(row)
|
|
|
|
.setComponents(
|
2022-12-17 13:33:33 +05:00
|
|
|
StringSelectMenuBuilder.from(menu)
|
2022-11-09 21:33:45 +05:00
|
|
|
.setMinValues(0)
|
|
|
|
.setMaxValues(menu.options.length + 1)
|
2022-12-15 21:02:38 +05:00
|
|
|
.addOptions(option),
|
2022-11-09 21:33:45 +05:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
row.addComponents(
|
2022-12-17 13:33:33 +05:00
|
|
|
new StringSelectMenuBuilder()
|
2022-11-09 21:33:45 +05:00
|
|
|
.setCustomId("auto_roles")
|
|
|
|
.setMinValues(0)
|
|
|
|
.setMaxValues(1)
|
|
|
|
.setPlaceholder(interaction.translate("common:AVAILABLE_OPTIONS"))
|
2022-12-15 21:02:38 +05:00
|
|
|
.addOptions(option),
|
2022-11-09 21:33:45 +05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
message.edit({
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [row],
|
2022-11-09 21:33:45 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
interaction.followUp({
|
|
|
|
content: interaction.translate("administration/selectroles:SUCCESS_ADDED", {
|
2022-12-15 21:02:38 +05:00
|
|
|
role: role.name,
|
2022-11-09 21:33:45 +05:00
|
|
|
}),
|
2022-12-15 21:02:38 +05:00
|
|
|
ephemeral: true,
|
2022-11-09 21:33:45 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Selectroles;
|