fix(moderation): tell a mute apart from a kick in the logs

A timeout was filed as "Exclusion temporaire" right next to "Expulsion",
so a sanction could not be read back from the log channel, the direct
message or `/mod logs`. Each action now carries its own emoji and wording
behind a single label, used by every surface.
This commit is contained in:
BlackAngelTV committed 2026-09-25 20:29:19 +02:00
1 parent 859b229181
commit 99e1fd2723
9 files changed
+73 -27

No files matched your search

+3 -4
View File
@@ -1,7 +1,7 @@
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'; import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
import { ACCESS_LEVELS, COLORS, MODERATION_ACTIONS } from '../../config/constants.js'; import { ACCESS_LEVELS, COLORS } from '../../config/constants.js';
import { listActions } from '../../database/repositories/moderation-repository.js'; import { listActions } from '../../database/repositories/moderation-repository.js';
import { formatDuration } from '../../services/moderation/moderation-service.js'; import { formatDuration, moderationLabel } from '../../services/moderation/moderation-service.js';
import { baseEmbed, infoEmbed } from '../../ui/embeds.js'; import { baseEmbed, infoEmbed } from '../../ui/embeds.js';
export const access = ACCESS_LEVELS.STAFF; export const access = ACCESS_LEVELS.STAFF;
@@ -20,11 +20,10 @@ export const data = new SlashCommandBuilder()
); );
function formatEntry(row) { function formatEntry(row) {
const meta = MODERATION_ACTIONS[row.action];
const target = row.target_id ? `<@${row.target_id}>` : 'salon'; const target = row.target_id ? `<@${row.target_id}>` : 'salon';
const duration = row.duration_ms ? ` pendant ${formatDuration(row.duration_ms)}` : ''; const duration = row.duration_ms ? ` pendant ${formatDuration(row.duration_ms)}` : '';
return ( return (
`\`${row.created_at}\` **${meta?.label ?? row.action}** — ${target}${duration}\n` + `\`${row.created_at}\` **${moderationLabel(row.action)}** — ${target}${duration}\n` +
`↳ par <@${row.moderator_id}> · ${row.reason || 'sans motif'}` `↳ par <@${row.moderator_id}> · ${row.reason || 'sans motif'}`
); );
} }
+2 -2
View File
@@ -40,7 +40,7 @@ export async function execute(interaction) {
assertModerationTarget(interaction, target); assertModerationTarget(interaction, target);
await interaction.deferReply({ flags: MessageFlags.Ephemeral }); await interaction.deferReply({ flags: MessageFlags.Ephemeral });
await target.timeout(durationMs, reason ?? `Exclusion temporaire de ${minutes} minutes`); await target.timeout(durationMs, reason ?? `Mise en sourdine de ${minutes} minutes`);
await logModerationAction(interaction, { await logModerationAction(interaction, {
action: 'mute', action: 'mute',
@@ -55,7 +55,7 @@ export async function execute(interaction) {
await interaction.editReply({ await interaction.editReply({
embeds: [ embeds: [
successEmbed( successEmbed(
`C’est fait : **${target.user.tag}** est en exclusion temporaire pour **${formatDuration(durationMs)}**, la personne ne peut plus écrire pendant ce temps.`, `C’est fait : **${target.user.tag}** est en sourdine pour **${formatDuration(durationMs)}**, la personne ne peut plus écrire pendant ce temps.`,
), ),
], ],
}); });
+19 -9
View File
@@ -28,16 +28,26 @@ export const ACCESS_LABELS = Object.freeze({
[ACCESS_LEVELS.OWNER]: 'Owner', [ACCESS_LEVELS.OWNER]: 'Owner',
}); });
/** Moderation actions: Discord label, embed color and stored duration (M8). */ /**
* Moderation actions: Discord label, embed color and stored duration (M8).
* The emoji belongs to the entry so every surface (log channel, direct message,
* `/mod logs`, dashboard) tells a mute from a kick at a glance: the wording
* alone read like a temporary kick.
*/
export const MODERATION_ACTIONS = Object.freeze({ export const MODERATION_ACTIONS = Object.freeze({
warn: { label: 'Avertissement', color: COLORS.warning, duration: false }, warn: { label: 'Avertissement', emoji: '⚠️', color: COLORS.warning, duration: false },
mute: { label: 'Exclusion temporaire', color: COLORS.moderation, duration: true }, mute: { label: 'Mise en sourdine', emoji: '🔇', color: COLORS.moderation, duration: true },
unmute: { label: 'Levée d’exclusion temporaire', color: COLORS.success, duration: false }, unmute: {
kick: { label: 'Expulsion', color: COLORS.moderation, duration: false }, label: 'Levée de la mise en sourdine',
ban: { label: 'Bannissement', color: COLORS.error, duration: false }, emoji: '🔊',
unban: { label: 'Débannissement', color: COLORS.success, duration: false }, color: COLORS.success,
clear: { label: 'Suppression de messages', color: COLORS.warning, duration: false }, duration: false,
role: { label: 'Modification de rôle', color: COLORS.primary, duration: false }, },
kick: { label: 'Expulsion', emoji: '👢', color: COLORS.moderation, duration: false },
ban: { label: 'Bannissement', emoji: '🔨', color: COLORS.error, duration: false },
unban: { label: 'Débannissement', emoji: '🔓', color: COLORS.success, duration: false },
clear: { label: 'Supclusion de messages', emoji: '🧹', color: COLORS.warning, duration: false },
role: { label: 'Modification de rôle', emoji: '🏷️', color: COLORS.primary, duration: false },
}); });
/** Ticket categories and who can see them (M0-T05 / M6-T01). */ /** Ticket categories and who can see them (M0-T05 / M6-T01). */
+1 -1
View File
@@ -91,7 +91,7 @@ export const GUILD_SETTINGS = Object.freeze([
{ {
key: 'moderation.defaultMuteMinutes', key: 'moderation.defaultMuteMinutes',
section: 'moderation', section: 'moderation',
label: 'Durée d’exclusion par défaut (min)', label: 'Durée de mise en sourdine par défaut (min)',
help: 'Proposée quand `/mute` est lancé sans durée.', help: 'Proposée quand `/mute` est lancé sans durée.',
type: 'int', type: 'int',
default: 60, default: 60,
+13 -2
View File
@@ -7,6 +7,17 @@ import { logEvent } from '../../database/repositories/event-log-repository.js';
import { recordAction } from '../../database/repositories/moderation-repository.js'; import { recordAction } from '../../database/repositories/moderation-repository.js';
import { baseEmbed } from '../../ui/embeds.js'; import { baseEmbed } from '../../ui/embeds.js';
/**
* Label shown for an action everywhere it is rendered (log channel, direct
* message, `/mod logs`, dashboard). Falls back to the raw action name, so a
* row written by another version still reads as something.
* @param {string} action
*/
export function moderationLabel(action) {
const meta = MODERATION_ACTIONS[action];
return meta ? `${meta.emoji} ${meta.label}` : action;
}
/** /**
* Enforces the role hierarchy before any moderation action (M3-T05 / M8-T08). * Enforces the role hierarchy before any moderation action (M3-T05 / M8-T08).
* @param {import('discord.js').ChatInputCommandInteraction} interaction * @param {import('discord.js').ChatInputCommandInteraction} interaction
@@ -82,7 +93,7 @@ export async function sendModerationLog(
const meta = MODERATION_ACTIONS[action]; const meta = MODERATION_ACTIONS[action];
const embed = baseEmbed(meta?.color) const embed = baseEmbed(meta?.color)
.setTitle(`🛡️ Modération — ${meta?.label ?? action}`) .setTitle(`🛡️ Modération — ${moderationLabel(action)}`)
.addFields( .addFields(
{ name: 'Membre', value: targetId ? `<@${targetId}> (${targetId})` : 'Salon', inline: true }, { name: 'Membre', value: targetId ? `<@${targetId}> (${targetId})` : 'Salon', inline: true },
{ name: 'Par', value: `<@${moderatorId}>`, inline: true }, { name: 'Par', value: `<@${moderatorId}>`, inline: true },
@@ -117,7 +128,7 @@ export function targetNoticeEmbed({ action, guildName, reason = null, durationMs
const embed = baseEmbed(meta?.color) const embed = baseEmbed(meta?.color)
.setTitle(`Sanction sur ${guildName}`) .setTitle(`Sanction sur ${guildName}`)
.setDescription( .setDescription(
`Action : **${meta?.label ?? action}**\n\nCette décision vient de l’équipe de modération. Tu peux répondre à ce message pour en parler calmement avec elle.`, `Action : **${moderationLabel(action)}**\n\nCette décision vient de l’équipe de modération. Tu peux répondre à ce message pour en parler calmement avec elle.`,
) )
.addFields({ name: 'Motif', value: reason || 'Non précisé' }); .addFields({ name: 'Motif', value: reason || 'Non précisé' });
if (durationMs) embed.addFields({ name: 'Durée', value: formatDuration(durationMs) }); if (durationMs) embed.addFields({ name: 'Durée', value: formatDuration(durationMs) });
+4 -4
View File
@@ -1,5 +1,5 @@
import { ChannelType, REST, Routes } from 'discord.js'; import { ChannelType, REST, Routes } from 'discord.js';
import { ACCESS_LABELS, ACCESS_LEVELS, MODERATION_ACTIONS } from '../../config/constants.js'; import { ACCESS_LABELS, ACCESS_LEVELS } from '../../config/constants.js';
import { env } from '../../config/env.js'; import { env } from '../../config/env.js';
import { ExternalApiError } from '../../core/errors.js'; import { ExternalApiError } from '../../core/errors.js';
import { createLogger } from '../../core/logger.js'; import { createLogger } from '../../core/logger.js';
@@ -15,7 +15,7 @@ import {
removeNotificationChannel, removeNotificationChannel,
setNotificationChannel, setNotificationChannel,
} from '../../database/repositories/notification-repository.js'; } from '../../database/repositories/notification-repository.js';
import { sendModerationLog } from '../../services/moderation/moderation-service.js'; import { moderationLabel, sendModerationLog } from '../../services/moderation/moderation-service.js';
import { badRequest, forbidden, notFound } from '../http.js'; import { badRequest, forbidden, notFound } from '../http.js';
/** Discord server management from the dashboard (M16-T05). */ /** Discord server management from the dashboard (M16-T05). */
@@ -201,7 +201,7 @@ export function registerDiscordRoutes(router) {
const reason = String(body.reason ?? '').trim() || 'Non précisé'; const reason = String(body.reason ?? '').trim() || 'Non précisé';
const durationMs = action === 'mute' ? Number.parseInt(body.durationMs ?? 0, 10) : null; const durationMs = action === 'mute' ? Number.parseInt(body.durationMs ?? 0, 10) : null;
if (action === 'mute' && (!Number.isInteger(durationMs) || durationMs <= 0)) { if (action === 'mute' && (!Number.isInteger(durationMs) || durationMs <= 0)) {
throw badRequest('Une durée en millisecondes est requise pour une exclusion temporaire.'); throw badRequest('Une durée en millisecondes est requise pour une mise en sourdine.');
} }
const audit = `${reason} — ${actor.displayName ?? actor.username} (tableau de bord)`; const audit = `${reason} — ${actor.displayName ?? actor.username} (tableau de bord)`;
@@ -231,7 +231,7 @@ export function registerDiscordRoutes(router) {
durationMs, durationMs,
}); });
return { ok: true, action, label: MODERATION_ACTIONS[action]?.label ?? action }; return { ok: true, action, label: moderationLabel(action) };
}, },
{ access: ACCESS_LEVELS.STAFF }, { access: ACCESS_LEVELS.STAFF },
); );
+6 -4
View File
@@ -33,11 +33,13 @@ const DURATIONS = [
{ value: String(7 * 24 * 60 * 60_000), label: '7 jours' }, { value: String(7 * 24 * 60 * 60_000), label: '7 jours' },
]; ];
// Mirrors MODERATION_ACTIONS in `src/config/constants.js`, emoji included: the
// panel must not be the one place where a mute reads like a kick.
const MODERATION_ACTIONS = [ const MODERATION_ACTIONS = [
{ value: 'warn', label: 'Avertissement' }, { value: 'warn', label: '⚠️ Avertissement' },
{ value: 'mute', label: 'Exclusion temporaire' }, { value: 'mute', label: '🔇 Mise en sourdine' },
{ value: 'kick', label: 'Expulsion' }, { value: 'kick', label: '👢 Expulsion' },
{ value: 'ban', label: 'Bannissement' }, { value: 'ban', label: '🔨 Bannissement' },
]; ];
async function moderate(member, reload) { async function moderate(member, reload) {
+1 -1
View File
@@ -230,7 +230,7 @@ export const VARIABLES = Object.freeze([
key: 'CHANNEL_MOD_LOGS_ID', key: 'CHANNEL_MOD_LOGS_ID',
section: 'channels', section: 'channels',
label: 'Salon des logs de modération', label: 'Salon des logs de modération',
help: 'Avertissements, exclusions, bannissements.', help: 'Avertissements, mises en sourdine, bannissements.',
type: 'snowflake', type: 'snowflake',
}, },
{ {
+24
View File
@@ -94,6 +94,30 @@ describe('webhook entry points', () => {
}); });
}); });
describe('moderation labels', () => {
it('tells every action apart by wording and emoji', async () => {
const { MODERATION_ACTIONS } = await import('../src/config/constants.js');
const { moderationLabel } = await import('../src/services/moderation/moderation-service.js');
const emojis = Object.values(MODERATION_ACTIONS).map((meta) => meta.emoji);
assert.ok(emojis.every(Boolean), 'an action has no emoji');
assert.equal(new Set(emojis).size, emojis.length, 'two actions share an emoji');
const labels = Object.keys(MODERATION_ACTIONS).map(moderationLabel);
assert.equal(new Set(labels).size, labels.length, 'two actions read the same');
assert.equal(moderationLabel('inconnu'), 'inconnu', 'an unknown action must stay readable');
});
it('never reads a mute like a kick', async () => {
// Reported from the moderation log channel: a timeout was filed as a
// temporary kick because both labels sat next to each other.
const { moderationLabel } = await import('../src/services/moderation/moderation-service.js');
assert.equal(moderationLabel('mute'), '🔇 Mise en sourdine');
assert.equal(moderationLabel('kick'), '👢 Expulsion');
});
});
describe('event modules', () => { describe('event modules', () => {
it('exports a name and a handler', async () => { it('exports a name and a handler', async () => {
const files = (await readdir(eventsDir)).filter((file) => file.endsWith('.js')); const files = (await readdir(eventsDir)).filter((file) => file.endsWith('.js'));