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:
9 files changed
+460
-30
No files matched your search
@@ -1,6 +1,12 @@
|
||||
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,
|
||||
logModerationAction,
|
||||
targetNoticeEmbed,
|
||||
} from '../../services/moderation/moderation-service.js';
|
||||
import { successEmbed } from '../../ui/embeds.js';
|
||||
|
||||
export const access = ACCESS_LEVELS.STAFF;
|
||||
|
||||
@@ -11,7 +17,24 @@ export const data = new SlashCommandBuilder()
|
||||
.addUserOption((option) => option.setName('user').setDescription('Membre').setRequired(true))
|
||||
.addStringOption((option) => option.setName('reason').setDescription('Raison').setMaxLength(500));
|
||||
|
||||
// TODO(M8-T03): kick after canActOn() check and log the action.
|
||||
/** Expels the member after the hierarchy checks (M8-T03 / M8-T06). */
|
||||
export async function execute(interaction) {
|
||||
await interaction.reply({ embeds: [notImplementedEmbed('/kick')] });
|
||||
const user = interaction.options.getUser('user', true);
|
||||
const reason = interaction.options.getString('reason');
|
||||
|
||||
const target = await fetchTargetMember(interaction, user.id);
|
||||
assertModerationTarget(interaction, target);
|
||||
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
await target
|
||||
.send({
|
||||
embeds: [targetNoticeEmbed({ action: 'kick', guildName: interaction.guild.name, reason })],
|
||||
})
|
||||
.catch(() => {});
|
||||
await target.kick(reason ?? `Expulsé par ${interaction.user.tag}`);
|
||||
|
||||
await logModerationAction(interaction, { action: 'kick', targetId: target.id, reason });
|
||||
await interaction.editReply({
|
||||
embeds: [successEmbed(`**${target.user.tag}** a été expulsé du serveur.`)],
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user