2023-07-03 21:13:08 +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 Clear 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("clear")
|
|
|
|
.setDescription(client.translate("moderation/clear:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("moderation/clear:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("moderation/clear: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("option")
|
|
|
|
.setDescription(client.translate("moderation/clear:OPTION"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("moderation/clear:OPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("moderation/clear:OPTION", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setRequired(true),
|
|
|
|
)
|
|
|
|
.addUserOption(option =>
|
|
|
|
option
|
|
|
|
.setName("user")
|
|
|
|
.setDescription(client.translate("common:USER"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("common:USER", null, "uk-UA"),
|
|
|
|
ru: client.translate("common:USER", null, "ru-RU"),
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName("id")
|
|
|
|
.setDescription(client.translate("common:USER_ID"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("common:USER_ID", null, "uk-UA"),
|
|
|
|
ru: client.translate("common:USER_ID", null, "ru-RU"),
|
|
|
|
}),
|
|
|
|
),
|
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
|
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
2022-08-28 21:53:54 +05:00
|
|
|
await interaction.deferReply({ ephemeral: true });
|
|
|
|
|
2023-03-26 18:31:19 +05:00
|
|
|
const option = interaction.options.getString("option"),
|
|
|
|
member = interaction.options.getMember("user"),
|
|
|
|
user_id = interaction.options.getString("id");
|
2022-08-06 20:47:47 +05:00
|
|
|
|
|
|
|
if (option === "all") {
|
2023-07-05 00:58:06 +05:00
|
|
|
const row = new ActionRowBuilder().addComponents(
|
|
|
|
new ButtonBuilder().setCustomId("clear_confirm_yes").setLabel(interaction.translate("common:ACCEPT")).setStyle(ButtonStyle.Danger),
|
|
|
|
new ButtonBuilder().setCustomId("clear_confirm_no").setLabel(interaction.translate("common:CANCEL")).setStyle(ButtonStyle.Secondary),
|
|
|
|
);
|
2022-08-06 20:47:47 +05:00
|
|
|
|
2022-08-28 21:53:54 +05:00
|
|
|
await interaction.editReply({
|
2022-08-06 20:47:47 +05:00
|
|
|
content: interaction.translate("moderation/clear:ALL_CONFIRM"),
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [row],
|
2022-08-06 20:47:47 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
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 === "clear_confirm_yes") {
|
2022-08-28 21:53:54 +05:00
|
|
|
i.deferUpdate();
|
|
|
|
|
2022-08-06 20:47:47 +05:00
|
|
|
const position = interaction.channel.position;
|
|
|
|
const newChannel = await interaction.channel.clone();
|
|
|
|
await interaction.channel.delete();
|
|
|
|
newChannel.setPosition(position);
|
|
|
|
|
2022-08-28 21:53:54 +05:00
|
|
|
return newChannel.send({
|
2022-12-15 21:02:38 +05:00
|
|
|
content: interaction.translate("moderation/clear:CHANNEL_CLEARED"),
|
2022-08-06 20:47:47 +05:00
|
|
|
});
|
|
|
|
} else if (i.customId === "clear_confirm_no") {
|
2022-08-28 21:53:54 +05:00
|
|
|
i.deferUpdate();
|
|
|
|
collector.stop("cancel");
|
2022-08-06 20:47:47 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-08-28 21:53:54 +05:00
|
|
|
|
|
|
|
collector.on("end", async (_, reason) => {
|
|
|
|
if (reason === "cancel") {
|
|
|
|
row.components.forEach(component => {
|
|
|
|
component.setDisabled(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
interaction.editReply({
|
|
|
|
content: interaction.translate("misc:SELECT_CANCELED"),
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [row],
|
2022-08-28 21:53:54 +05:00
|
|
|
});
|
|
|
|
} else if (reason === "idle") {
|
|
|
|
row.components.forEach(component => {
|
|
|
|
component.setDisabled(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
interaction.editReply({
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [row],
|
2022-08-28 21:53:54 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-08-06 20:47:47 +05:00
|
|
|
} else {
|
2022-08-09 23:48:33 +05:00
|
|
|
if (isNaN(option) || parseInt(option) < 1) return interaction.error("misc:OPTION_NAN_ALL", null, { ephemeral: true });
|
2023-03-26 18:31:19 +05:00
|
|
|
|
2024-04-07 20:14:04 +05:00
|
|
|
let messages = await interaction.channel.messages.fetch({ limit: option });
|
2023-03-26 18:31:19 +05:00
|
|
|
|
2023-03-28 10:35:46 +05:00
|
|
|
if (user_id && member) return interaction.replyT("moderation/clear:REQUIRE_ID_USER", null, { edit: true });
|
|
|
|
if (user_id || member) messages = messages.filter(m => m.author.id === (user_id || member.id));
|
2022-08-06 20:47:47 +05:00
|
|
|
|
2024-04-07 20:14:04 +05:00
|
|
|
interaction.channel.bulkDelete(messages.filter(m => !m.pinned), true);
|
2022-08-06 20:47:47 +05:00
|
|
|
|
2023-03-26 18:31:19 +05:00
|
|
|
if (member || user_id) {
|
2022-08-06 20:47:47 +05:00
|
|
|
interaction.replyT("moderation/clear:CLEARED_MEMBER", {
|
2023-04-20 11:47:47 +05:00
|
|
|
amount: `**${option}** ${client.functions.getNoun(option, interaction.translate("misc:NOUNS:MESSAGES:1"), interaction.translate("misc:NOUNS:MESSAGES:2"), interaction.translate("misc:NOUNS:MESSAGES:5"))}`,
|
2024-04-07 20:14:04 +05:00
|
|
|
user: user_id || member.toString(),
|
2023-03-26 18:31:19 +05:00
|
|
|
}, { edit: true });
|
2022-08-06 20:47:47 +05:00
|
|
|
} else {
|
|
|
|
interaction.replyT("moderation/clear:CLEARED", {
|
2023-04-20 11:47:47 +05:00
|
|
|
amount: `**${option}** ${client.functions.getNoun(option, interaction.translate("misc:NOUNS:MESSAGES:1"), interaction.translate("misc:NOUNS:MESSAGES:2"), interaction.translate("misc:NOUNS:MESSAGES:5"))}`,
|
2023-03-26 18:31:19 +05:00
|
|
|
}, { edit: true });
|
2022-08-06 20:47:47 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Clear;
|