feat(moderation): implement the moderation service and commands

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.
This commit is contained in:
BlackAngelTV committed 2026-09-15 14:50:48 +02:00
1 parent e8c95b2ba3
commit c49c60071d
9 files changed
+460 -30

No files matched your search

+26 -4
View File
@@ -1,6 +1,8 @@
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
import { ACCESS_LEVELS } from '../../config/constants.js';
import { notImplementedEmbed } from '../../ui/embeds.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;
@@ -17,7 +19,27 @@ export const data = new SlashCommandBuilder()
.setMaxValue(100),
);
// TODO(M8-T05): channel.bulkDelete(amount, true) and log the action.
/** Bulk deletes messages in the current channel and logs it (M8-T05). */
export async function execute(interaction) {
await interaction.reply({ embeds: [notImplementedEmbed('/clear')] });
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._' : ''),
),
],
});
}