Files
FWS-DiscordBot/src/commands/moderation/mute.js
T
nocodeandClaude Opus 5 7d568e416d feat(settings): make the server settings real, and widen them
The dashboard offered seven switches that nothing read: they promised a
behaviour the bot did not have, which is worse than offering nothing.

Every setting is now declared once, with its type, its bounds and its
explanation, and the services read it: the welcome message and its wording,
the automatic role, departure notices, the private notice sent to a
sanctioned member, the default mute duration, how much history a ban erases,
whether a closed ticket is deleted or archived, and an optional role mention
on the Gitea notifications.

A test walks the sources and fails when a declared key is read nowhere, so
the list cannot drift back into decoration.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 21:48:18 +02:00

63 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
import { ACCESS_LEVELS } from '../../config/constants.js';
import { readSetting } from '../../config/guild-settings.js';
import {
assertModerationTarget,
fetchTargetMember,
formatDuration,
logModerationAction,
notifyTarget,
targetNoticeEmbed,
} from '../../services/moderation/moderation-service.js';
import { successEmbed } from '../../ui/embeds.js';
export const access = ACCESS_LEVELS.STAFF;
export const data = new SlashCommandBuilder()
.setName('mute')
.setDescription('Restreindre temporairement un membre')
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
.addUserOption((option) => option.setName('user').setDescription('Membre').setRequired(true))
.addIntegerOption((option) =>
option
.setName('minutes')
.setDescription('Durée de la sanction, en minutes')
.setMinValue(1)
.setMaxValue(40_320),
)
.addStringOption((option) => option.setName('reason').setDescription('Motif').setMaxLength(500));
/** Applies a Discord timeout after the hierarchy checks (M8-T02 / M8-T07). */
export async function execute(interaction) {
const user = interaction.options.getUser('user', true);
const minutes =
interaction.options.getInteger('minutes') ??
readSetting('moderation.defaultMuteMinutes', interaction.guildId);
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 notifyTarget(target, {
embeds: [targetNoticeEmbed({ action: 'mute', guildName: interaction.guild.name, reason, durationMs })],
});
await interaction.editReply({
embeds: [
successEmbed(
`C’est fait : **${target.user.tag}** est en exclusion temporaire pour **${formatDuration(durationMs)}**, la personne ne peut plus écrire pendant ce temps.`,
),
],
});
}