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

+38 -4
View File
@@ -1,6 +1,13 @@
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 {
assertModerationTarget,
fetchTargetMember,
formatDuration,
logModerationAction,
targetNoticeEmbed,
} from '../../services/moderation/moderation-service.js';
import { successEmbed } from '../../ui/embeds.js';
export const access = ACCESS_LEVELS.STAFF;
@@ -19,7 +26,34 @@ export const data = new SlashCommandBuilder()
)
.addStringOption((option) => option.setName('reason').setDescription('Raison').setMaxLength(500));
// TODO(M8-T02 / M8-T07): use member.timeout() after canActOn() check.
/** Applies a Discord timeout after the hierarchy checks (M8-T02 / M8-T07). */
export async function execute(interaction) {
await interaction.reply({ embeds: [notImplementedEmbed('/mute')] });
const user = interaction.options.getUser('user', true);
const minutes = interaction.options.getInteger('minutes', true);
const reason = interaction.options.getString('reason');
const durationMs = minutes * 60_000;
const target = await fetchTargetMember(interaction, user.id);
assertModerationTarget(interaction, target);
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
await target.timeout(durationMs, reason ?? `Exclusion temporaire de ${minutes} minutes`);
await logModerationAction(interaction, {
action: 'mute',
targetId: target.id,
reason,
durationMs,
});
await target
.send({
embeds: [targetNoticeEmbed({ action: 'mute', guildName: interaction.guild.name, reason, durationMs })],
})
.catch(() => {});
await interaction.editReply({
embeds: [
successEmbed(`**${target.user.tag}** est réduit au silence pendant **${formatDuration(durationMs)}**.`),
],
});
}