2024-09-19 23:58:06 +05:00
|
|
|
const { SlashCommandBuilder, PermissionsBitField, ActionRowBuilder, StringSelectMenuBuilder, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
|
2022-11-09 21:33:45 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Selectroles extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-11-09 21:33:45 +05:00
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("selectroles")
|
|
|
|
.setDescription(client.translate("administration/selectroles:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("administration/selectroles:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("administration/selectroles:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2024-09-19 23:58:06 +05:00
|
|
|
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall])
|
2024-09-14 19:52:56 +05:00
|
|
|
.setContexts([InteractionContextType.Guild])
|
2023-07-03 21:13:08 +05:00
|
|
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageGuild)
|
2023-07-05 00:58:06 +05:00
|
|
|
.addSubcommand(subcommand =>
|
|
|
|
subcommand
|
|
|
|
.setName("message")
|
|
|
|
.setDescription(client.translate("administration/selectroles:MESSAGE"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("administration/selectroles:MESSAGE", null, "uk-UA"),
|
|
|
|
ru: client.translate("administration/selectroles:MESSAGE", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2023-07-05 00:58:06 +05:00
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName("text")
|
|
|
|
.setDescription(client.translate("common:MESSAGE"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("common:MESSAGE", null, "uk-UA"),
|
|
|
|
ru: client.translate("common:MESSAGE", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setRequired(true),
|
|
|
|
),
|
2022-11-09 21:33:45 +05:00
|
|
|
)
|
2023-07-05 00:58:06 +05:00
|
|
|
.addSubcommand(subcommand =>
|
|
|
|
subcommand
|
|
|
|
.setName("addrole")
|
|
|
|
.setDescription(client.translate("administration/selectroles:ADDROLE"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("administration/selectroles:ADDROLE", null, "uk-UA"),
|
|
|
|
ru: client.translate("administration/selectroles:ADDROLE", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2023-07-05 00:58:06 +05:00
|
|
|
.addChannelOption(option =>
|
|
|
|
option
|
|
|
|
.setName("channel")
|
|
|
|
.setDescription(client.translate("common:CHANNEL"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("common:CHANNEL", null, "uk-UA"),
|
|
|
|
ru: client.translate("common:CHANNEL", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setRequired(true),
|
|
|
|
)
|
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName("message_id")
|
|
|
|
.setDescription(client.translate("common:MESSAGE_ID"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("common:MESSAGE_ID", null, "uk-UA"),
|
|
|
|
ru: client.translate("common:MESSAGE_ID", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setRequired(true),
|
|
|
|
)
|
|
|
|
.addRoleOption(option =>
|
|
|
|
option
|
|
|
|
.setName("role")
|
|
|
|
.setDescription(client.translate("common:ROLE"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("common:ROLE", null, "uk-UA"),
|
|
|
|
ru: client.translate("common:ROLE", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setRequired(true),
|
|
|
|
),
|
2022-11-09 21:33:45 +05:00
|
|
|
),
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-11-09 21:33:45 +05:00
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2022-11-09 21:33:45 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-11-09 21:33:45 +05:00
|
|
|
*/
|
|
|
|
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") {
|
2024-02-09 23:26:57 +05:00
|
|
|
interaction.data = [];
|
2024-05-24 23:11:03 +05:00
|
|
|
interaction.data.guild = await client.getGuildData(interaction.guildId);
|
2024-02-09 23:26:57 +05:00
|
|
|
|
2022-11-09 21:33:45 +05:00
|
|
|
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({
|
2023-11-04 23:06:51 +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
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2022-11-09 21:33:45 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-11-09 21:33:45 +05:00
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
|
|
*/
|
|
|
|
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();
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
const option = [
|
|
|
|
{
|
|
|
|
label: role.name,
|
|
|
|
value: role.id,
|
|
|
|
},
|
|
|
|
];
|
2022-11-09 21:33:45 +05:00
|
|
|
|
|
|
|
const menu = row.components[0];
|
|
|
|
if (menu) {
|
|
|
|
for (const o of menu.options) {
|
2023-10-17 16:54:26 +05:00
|
|
|
if (o.value === option[0].value) return interaction.error("administration/selectroles:ALREADY_IN_MENU", null, { edit: true });
|
2022-11-09 21:33:45 +05:00
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
row = ActionRowBuilder.from(row).setComponents(
|
|
|
|
StringSelectMenuBuilder.from(menu)
|
2022-11-09 21:33:45 +05:00
|
|
|
.setMinValues(0)
|
2023-07-05 00:58:06 +05:00
|
|
|
.setMaxValues(menu.options.length + 1)
|
2022-12-15 21:02:38 +05:00
|
|
|
.addOptions(option),
|
2022-11-09 21:33:45 +05:00
|
|
|
);
|
2023-07-05 00:58:06 +05:00
|
|
|
} else {
|
|
|
|
row.addComponents(new StringSelectMenuBuilder().setCustomId("auto_roles").setMinValues(0).setMaxValues(1).setPlaceholder(interaction.translate("common:AVAILABLE_OPTIONS")).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
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Selectroles;
|