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

+32 -4
View File
@@ -1,6 +1,11 @@
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,
logModerationAction,
targetNoticeEmbed,
} from '../../services/moderation/moderation-service.js';
import { successEmbed } from '../../ui/embeds.js';
export const access = ACCESS_LEVELS.STAFF;
@@ -18,7 +23,30 @@ export const data = new SlashCommandBuilder()
.setMaxValue(7),
);
// TODO(M8-T04): ban after canActOn() check and log the sensitive action (M8-T09).
/** Bans the user, whether or not they are still on the server (M8-T04 / M8-T09). */
export async function execute(interaction) {
await interaction.reply({ embeds: [notImplementedEmbed('/ban')] });
const user = interaction.options.getUser('user', true);
const reason = interaction.options.getString('reason');
const deleteDays = interaction.options.getInteger('delete_days') ?? 0;
const member = await interaction.guild.members.fetch(user.id).catch(() => null);
if (member) {
assertModerationTarget(interaction, member);
await member
.send({
embeds: [targetNoticeEmbed({ action: 'ban', guildName: interaction.guild.name, reason })],
})
.catch(() => {});
}
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
await interaction.guild.bans.create(user.id, {
reason: reason ?? `Banni par ${interaction.user.tag}`,
deleteMessageSeconds: deleteDays * 86_400,
});
await logModerationAction(interaction, { action: 'ban', targetId: user.id, reason });
await interaction.editReply({
embeds: [successEmbed(`**${user.tag}** a été banni du serveur.`)],
});
}