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

+34 -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 { countActions } from '../../database/repositories/moderation-repository.js';
import {
assertModerationTarget,
fetchTargetMember,
logModerationAction,
targetNoticeEmbed,
} from '../../services/moderation/moderation-service.js';
import { successEmbed } from '../../ui/embeds.js';
export const access = ACCESS_LEVELS.STAFF;
@@ -13,7 +20,30 @@ export const data = new SlashCommandBuilder()
option.setName('reason').setDescription('Raison').setRequired(true).setMaxLength(500),
);
// TODO(M8-T01): record in moderation_actions and log (M8-T06).
/** Records the warning, notifies the member and logs it (M8-T01 / M8-T06). */
export async function execute(interaction) {
await interaction.reply({ embeds: [notImplementedEmbed('/warn')] });
const user = interaction.options.getUser('user', true);
const reason = interaction.options.getString('reason', true);
const target = await fetchTargetMember(interaction, user.id);
assertModerationTarget(interaction, target);
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
await logModerationAction(interaction, { action: 'warn', targetId: target.id, reason });
const total = countActions({ guildId: interaction.guildId, targetId: target.id, action: 'warn' });
await target
.send({
embeds: [
targetNoticeEmbed({ action: 'warn', guildName: interaction.guild.name, reason }).addFields({
name: 'Avertissements',
value: String(total),
}),
],
})
.catch(() => {});
await interaction.editReply({
embeds: [successEmbed(`**${target.user.tag}** a été averti (${total} avertissement(s) au total).`)],
});
}