Every action checks the role hierarchy before touching Discord, then records the sanction in SQLite and mirrors it in the moderation log channel, so the history outlives the audit log.
46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||
import { ACCESS_LEVELS } from '../../config/constants.js';
|
||
import { UserFacingError } from '../../core/errors.js';
|
||
import { logModerationAction } from '../../services/moderation/moderation-service.js';
|
||
import { successEmbed } from '../../ui/embeds.js';
|
||
|
||
export const access = ACCESS_LEVELS.STAFF;
|
||
|
||
export const data = new SlashCommandBuilder()
|
||
.setName('clear')
|
||
.setDescription('Supprimer des messages')
|
||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
|
||
.addIntegerOption((option) =>
|
||
option
|
||
.setName('amount')
|
||
.setDescription('Nombre de messages')
|
||
.setRequired(true)
|
||
.setMinValue(1)
|
||
.setMaxValue(100),
|
||
);
|
||
|
||
/** Bulk deletes messages in the current channel and logs it (M8-T05). */
|
||
export async function execute(interaction) {
|
||
const amount = interaction.options.getInteger('amount', true);
|
||
if (!interaction.channel?.isTextBased() || !interaction.channel.bulkDelete) {
|
||
throw new UserFacingError('La suppression groupée n’est pas possible dans ce salon.');
|
||
}
|
||
|
||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||
const deleted = await interaction.channel.bulkDelete(amount, true);
|
||
|
||
await logModerationAction(interaction, {
|
||
action: 'clear',
|
||
targetId: null,
|
||
reason: `${deleted.size} message(s) supprimé(s) dans #${interaction.channel.name}`,
|
||
});
|
||
await interaction.editReply({
|
||
embeds: [
|
||
successEmbed(
|
||
`${deleted.size} message(s) supprimé(s) dans <#${interaction.channelId}>.` +
|
||
(deleted.size < amount ? '\n_Les messages de plus de 14 jours sont conservés par Discord._' : ''),
|
||
),
|
||
],
|
||
});
|
||
}
|