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:
9 files changed
+73
-27
No files matched your search
@@ -1,7 +1,7 @@
|
||||
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 { formatDuration } from '../../services/moderation/moderation-service.js';
|
||||
import { formatDuration, moderationLabel } from '../../services/moderation/moderation-service.js';
|
||||
import { baseEmbed, infoEmbed } from '../../ui/embeds.js';
|
||||
|
||||
export const access = ACCESS_LEVELS.STAFF;
|
||||
@@ -20,11 +20,10 @@ export const data = new SlashCommandBuilder()
|
||||
);
|
||||
|
||||
function formatEntry(row) {
|
||||
const meta = MODERATION_ACTIONS[row.action];
|
||||
const target = row.target_id ? `<@${row.target_id}>` : 'salon';
|
||||
const duration = row.duration_ms ? ` pendant ${formatDuration(row.duration_ms)}` : '';
|
||||
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'}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ export async function execute(interaction) {
|
||||
assertModerationTarget(interaction, target);
|
||||
|
||||
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, {
|
||||
action: 'mute',
|
||||
@@ -55,7 +55,7 @@ export async function execute(interaction) {
|
||||
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.`,
|
||||
`C’est fait : **${target.user.tag}** est en sourdine pour **${formatDuration(durationMs)}**, la personne ne peut plus écrire pendant ce temps.`,
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
+19
-9
@@ -28,16 +28,26 @@ export const ACCESS_LABELS = Object.freeze({
|
||||
[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({
|
||||
warn: { label: 'Avertissement', color: COLORS.warning, duration: false },
|
||||
mute: { label: 'Exclusion temporaire', color: COLORS.moderation, duration: true },
|
||||
unmute: { label: 'Levée d’exclusion temporaire', color: COLORS.success, duration: false },
|
||||
kick: { label: 'Expulsion', color: COLORS.moderation, duration: false },
|
||||
ban: { label: 'Bannissement', color: COLORS.error, duration: false },
|
||||
unban: { label: 'Débannissement', color: COLORS.success, duration: false },
|
||||
clear: { label: 'Suppression de messages', color: COLORS.warning, duration: false },
|
||||
role: { label: 'Modification de rôle', color: COLORS.primary, duration: false },
|
||||
warn: { label: 'Avertissement', emoji: '⚠️', color: COLORS.warning, duration: false },
|
||||
mute: { label: 'Mise en sourdine', emoji: '🔇', color: COLORS.moderation, duration: true },
|
||||
unmute: {
|
||||
label: 'Levée de la mise en sourdine',
|
||||
emoji: '🔊',
|
||||
color: COLORS.success,
|
||||
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). */
|
||||
|
||||
@@ -91,7 +91,7 @@ export const GUILD_SETTINGS = Object.freeze([
|
||||
{
|
||||
key: 'moderation.defaultMuteMinutes',
|
||||
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.',
|
||||
type: 'int',
|
||||
default: 60,
|
||||
|
||||
@@ -7,6 +7,17 @@ import { logEvent } from '../../database/repositories/event-log-repository.js';
|
||||
import { recordAction } from '../../database/repositories/moderation-repository.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).
|
||||
* @param {import('discord.js').ChatInputCommandInteraction} interaction
|
||||
@@ -82,7 +93,7 @@ export async function sendModerationLog(
|
||||
|
||||
const meta = MODERATION_ACTIONS[action];
|
||||
const embed = baseEmbed(meta?.color)
|
||||
.setTitle(`🛡️ Modération — ${meta?.label ?? action}`)
|
||||
.setTitle(`🛡️ Modération — ${moderationLabel(action)}`)
|
||||
.addFields(
|
||||
{ name: 'Membre', value: targetId ? `<@${targetId}> (${targetId})` : 'Salon', 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)
|
||||
.setTitle(`Sanction sur ${guildName}`)
|
||||
.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é' });
|
||||
if (durationMs) embed.addFields({ name: 'Durée', value: formatDuration(durationMs) });
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 { ExternalApiError } from '../../core/errors.js';
|
||||
import { createLogger } from '../../core/logger.js';
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
removeNotificationChannel,
|
||||
setNotificationChannel,
|
||||
} 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';
|
||||
|
||||
/** 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 durationMs = action === 'mute' ? Number.parseInt(body.durationMs ?? 0, 10) : null;
|
||||
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)`;
|
||||
@@ -231,7 +231,7 @@ export function registerDiscordRoutes(router) {
|
||||
durationMs,
|
||||
});
|
||||
|
||||
return { ok: true, action, label: MODERATION_ACTIONS[action]?.label ?? action };
|
||||
return { ok: true, action, label: moderationLabel(action) };
|
||||
},
|
||||
{ access: ACCESS_LEVELS.STAFF },
|
||||
);
|
||||
|
||||
@@ -33,11 +33,13 @@ const DURATIONS = [
|
||||
{ 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 = [
|
||||
{ value: 'warn', label: 'Avertissement' },
|
||||
{ value: 'mute', label: 'Exclusion temporaire' },
|
||||
{ value: 'kick', label: 'Expulsion' },
|
||||
{ value: 'ban', label: 'Bannissement' },
|
||||
{ value: 'warn', label: '⚠️ Avertissement' },
|
||||
{ value: 'mute', label: '🔇 Mise en sourdine' },
|
||||
{ value: 'kick', label: '👢 Expulsion' },
|
||||
{ value: 'ban', label: '🔨 Bannissement' },
|
||||
];
|
||||
|
||||
async function moderate(member, reload) {
|
||||
|
||||
@@ -230,7 +230,7 @@ export const VARIABLES = Object.freeze([
|
||||
key: 'CHANNEL_MOD_LOGS_ID',
|
||||
section: 'channels',
|
||||
label: 'Salon des logs de modération',
|
||||
help: 'Avertissements, exclusions, bannissements.',
|
||||
help: 'Avertissements, mises en sourdine, bannissements.',
|
||||
type: 'snowflake',
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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', () => {
|
||||
it('exports a name and a handler', async () => {
|
||||
const files = (await readdir(eventsDir)).filter((file) => file.endsWith('.js'));
|
||||
|
||||
Reference in new issue
Block a user