Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c61a13176e
|
||
|
|
44e990d04b
|
||
|
|
99e1fd2723
|
||
|
|
859b229181 | ||
|
|
d720c0a17e
|
||
|
|
9f8ac0d29e
|
||
|
|
b8be549fda
|
No files matched your search
@@ -1,12 +1,12 @@
|
|||||||
# AGENTS.md — Instructions pour les agents IA
|
# AGENTS.md — Instructions pour les agents IA
|
||||||
|
|
||||||
> Fichier de référence pour les agents IA (Codebuff, Cursor, Claude Code, GitHub Copilot…) qui travaillent sur un repo de l'organisation **FWS**. Un agent doit lire ce fichier en premier : il contient les instructions à respecter. Le `README.md` apporte le contexte complet.
|
> Fichier de référence pour les agents IA (Codebuff, Cursor, Claude Code, GitHub Copilot…) qui travaillent sur un dépôt de l'organisation **FWS**. Un agent doit lire ce fichier en premier : il contient les instructions à respecter. Le `README.md` présente l'organisation et le `CONTRIBUTING.md` détaille les conventions de collaboration.
|
||||||
|
|
||||||
## Contexte
|
## Contexte
|
||||||
|
|
||||||
- **FWS** est une organisation open source multi-projets : chaque projet choisit librement sa stack (pas de restriction de langage).
|
- **FWS** est une organisation open source multi-projets : chaque projet choisit librement sa stack technique (sans restriction de langage).
|
||||||
- Projet principal : **FWS Arch** — un fork d'Arch Linux avec une surcouche conviviale pour simplifier l'installation et l'usage au quotidien.
|
- Projet principal : **FWS ISO** — une distribution Linux basée sur Arch Linux, pensée pour simplifier l'installation et l'usage au quotidien.
|
||||||
- Conventions détaillées : `README.md` (FR) / `README.en.md` (EN).
|
- Conventions détaillées : `CONTRIBUTING.md` (FR) / `CONTRIBUTING.en.md` (EN).
|
||||||
|
|
||||||
## Règles à respecter
|
## Règles à respecter
|
||||||
|
|
||||||
@@ -24,29 +24,36 @@
|
|||||||
|
|
||||||
### Code & commentaires
|
### Code & commentaires
|
||||||
|
|
||||||
- Commentaires en **anglais**, style « pourquoi » : pas de commentaire si le code est explicite, documenter le non-évident (choix d'implémentation, trade-offs, cas limites).
|
- Commentaires en **anglais**, style « pourquoi » : pas de commentaire si le code est explicite ; documenter le non-évident (choix d'implémentation, compromis, cas limites).
|
||||||
- Respecter la stack et les conventions existantes du repo avant d'ajouter de nouvelles dépendances.
|
- Respecter la stack technique et les conventions existantes du dépôt avant d'ajouter de nouvelles dépendances.
|
||||||
|
|
||||||
### Fichiers sensibles (`.gitignore`)
|
### Fichiers sensibles (`.gitignore`)
|
||||||
|
|
||||||
- Ne **jamais** committer : fichiers d'environnement (`.env*`), données d'assistants de développement (`.freebuff/`), artefacts compilés (`dist/`, `build/`, `target/`, `__pycache__/`…), dépendances (`node_modules/`), secrets.
|
- Ne **jamais** versionner : fichiers d'environnement (`.env*`), données d'assistants de développement (`.freebuff/`), artefacts compilés (`dist/`, `build/`, `target/`, `__pycache__/`…), dépendances (`node_modules/`), secrets.
|
||||||
- Un `.gitignore` doit exister à la racine de chaque repo.
|
- Un `.gitignore` doit exister à la racine de chaque dépôt.
|
||||||
|
|
||||||
### Tests
|
### Tests
|
||||||
|
|
||||||
- Fichiers de test : `*.test.*`, noms `describe` / `it` en anglais.
|
- Fichiers de test : `*.test.*` ; noms de tests `describe` / `it` en anglais.
|
||||||
- Vérifier que les tests (et le typecheck / lint quand ils existent) passent avant de considérer une tâche terminée.
|
- Vérifier que les tests (et le typecheck / lint quand ils existent) passent avant de considérer une tâche terminée.
|
||||||
|
|
||||||
### Issues & signalement de bugs
|
### Issues & signalement de bugs
|
||||||
|
|
||||||
- Les bugs et demandes sont suivis via les **issues**, liées au tableau Kanban.
|
- Les bugs et demandes sont suivis via les **issues** et, lorsqu'il existe, le tableau Kanban du projet.
|
||||||
- Une PR qui corrige un bug référence l'issue dans son titre ou sa description (`Fixes #123`).
|
- Une pull request qui corrige un bug référence l'issue dans son titre ou sa description (`Fixes #123`).
|
||||||
- Ne pas fermer ni modifier une issue sans demande explicite de l'utilisateur.
|
- Ne pas fermer ni modifier une issue sans demande explicite de l'utilisateur.
|
||||||
|
|
||||||
|
### Commits demandés par l'utilisateur
|
||||||
|
|
||||||
|
- Lorsque l'utilisateur demande explicitement de créer un commit, l'IA doit le faire après avoir vérifié les changements et les contrôles disponibles, sans attendre une confirmation supplémentaire.
|
||||||
|
- Le titre et le corps du commit ne doivent jamais mentionner l'IA, l'assistant, Codebuff ou l'outil utilisé.
|
||||||
|
- Ne pas ajouter l'IA comme auteur ou co-auteur dans le message du commit.
|
||||||
|
|
||||||
## Bonnes pratiques pour un agent
|
## Bonnes pratiques pour un agent
|
||||||
|
|
||||||
- Lire `AGENTS.md` puis `README.md` avant d'éditer du code.
|
- Lire `AGENTS.md`, le `README.md` et le `CONTRIBUTING.md` avant d'éditer du code.
|
||||||
|
- Les commits doivent être signés.
|
||||||
- Faire les changements les plus petits possibles qui répondent à la demande.
|
- Faire les changements les plus petits possibles qui répondent à la demande.
|
||||||
- Ne pas pousser, merger ni publier sans demande explicite de l'utilisateur.
|
- Ne pas pousser, fusionner ni publier sans demande explicite de l'utilisateur.
|
||||||
- Suivre les cartes du tableau Kanban du projet pour l'organisation du travail.
|
- Suivre les cartes du tableau Kanban lorsqu'il existe pour organiser le travail.
|
||||||
- En cas de doute, demander plutôt que deviner.
|
- En cas de doute, demander plutôt que de deviner.
|
||||||
@@ -7,6 +7,7 @@ The project follows [Semantic Versioning](https://semver.org/).
|
|||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
- **moderation:** _(feat)_ add the unmute and unban commands ([9f8ac0d])
|
||||||
- **web:** _(feat)_ publish a public status page at /status ([a1e1de7])
|
- **web:** _(feat)_ publish a public status page at /status ([a1e1de7])
|
||||||
- **web:** _(feat)_ search the whole panel from one place ([9acb523])
|
- **web:** _(feat)_ search the whole panel from one place ([9acb523])
|
||||||
- **projects:** _(feat)_ gather the cards one member carries ([fcc82d8])
|
- **projects:** _(feat)_ gather the cards one member carries ([fcc82d8])
|
||||||
@@ -91,6 +92,7 @@ The project follows [Semantic Versioning](https://semver.org/).
|
|||||||
- **config:** _(feat)_ load and expose environment settings ([d1388b6])
|
- **config:** _(feat)_ load and expose environment settings ([d1388b6])
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
- **moderation:** _(fix)_ tell a mute apart from a kick in the logs ([99e1fd2])
|
||||||
- **wiki:** _(fix)_ render the public pages on the server ([8869c74])
|
- **wiki:** _(fix)_ render the public pages on the server ([8869c74])
|
||||||
- **web:** _(fix)_ stop caching the interface modules ([3f4a570])
|
- **web:** _(fix)_ stop caching the interface modules ([3f4a570])
|
||||||
- **web:** _(fix)_ keep the stack when a view fails ([c031b4d])
|
- **web:** _(fix)_ keep the stack when a view fails ([c031b4d])
|
||||||
@@ -109,6 +111,7 @@ The project follows [Semantic Versioning](https://semver.org/).
|
|||||||
- **notifications:** _(fix)_ apply the channel overrides set from Discord ([92405ac])
|
- **notifications:** _(fix)_ apply the channel overrides set from Discord ([92405ac])
|
||||||
|
|
||||||
### Other changes
|
### Other changes
|
||||||
|
- **agents:** _(docs)_ update the repository conventions and commit rules ([44e990d])
|
||||||
- **web:** _(docs)_ document my tasks, the search and the status page ([566af4d])
|
- **web:** _(docs)_ document my tasks, the search and the status page ([566af4d])
|
||||||
- **web:** _(refactor)_ extract the build marker into its own module ([d2256e2])
|
- **web:** _(refactor)_ extract the build marker into its own module ([d2256e2])
|
||||||
- **ops:** _(docs)_ correct the deployment path for a panel without a shell ([e3ce266])
|
- **ops:** _(docs)_ correct the deployment path for a panel without a shell ([e3ce266])
|
||||||
|
|||||||
@@ -289,6 +289,8 @@ Every command checks the FWS level **and** the matching Discord permission. The
|
|||||||
| ---------------- | ----------------------------------------- | ------------------ | ----- | ------------------------------------------------------------------ |
|
| ---------------- | ----------------------------------------- | ------------------ | ----- | ------------------------------------------------------------------ |
|
||||||
| `/warn` | `user`, `reason` (required) | Moderate Members | ✅ | Warns, notifies the member by DM and records the action |
|
| `/warn` | `user`, `reason` (required) | Moderate Members | ✅ | Warns, notifies the member by DM and records the action |
|
||||||
| `/mute` | `user`, `minutes` (1–40320), `reason` | Moderate Members | ✅ | Temporary timeout (28 days max) + DM notification |
|
| `/mute` | `user`, `minutes` (1–40320), `reason` | Moderate Members | ✅ | Temporary timeout (28 days max) + DM notification |
|
||||||
|
| `/unmute` | `user`, `reason` | Moderate Members | ✅ | Lifts the timeout early (clear message when nobody is muted) |
|
||||||
|
| `/unban` | `user`, `reason` | Ban Members | ✅ | Lifts the ban, even if the member already left, and DMs them |
|
||||||
| `/kick` | `user`, `reason` | Kick Members | ✅ | Kicks from the server and logs the action |
|
| `/kick` | `user`, `reason` | Kick Members | ✅ | Kicks from the server and logs the action |
|
||||||
| `/ban` | `user`, `reason`, `delete_days` (0–7) | Ban Members | ✅ | Bans (even if the member already left), optional message purge |
|
| `/ban` | `user`, `reason`, `delete_days` (0–7) | Ban Members | ✅ | Bans (even if the member already left), optional message purge |
|
||||||
| `/clear` | `amount` (1–100) | Manage Messages | ✅ | Deletes the last N messages (those older than 14 days are skipped) |
|
| `/clear` | `amount` (1–100) | Manage Messages | ✅ | Deletes the last N messages (those older than 14 days are skipped) |
|
||||||
|
|||||||
@@ -291,6 +291,8 @@ Chaque commande vérifie le niveau FWS **et** la permission Discord correspondan
|
|||||||
| --- | --- | --- | --- | --- |
|
| --- | --- | --- | --- | --- |
|
||||||
| `/warn` | `user`, `reason` (obligatoires) | Modérer les membres | ✅ | Avertit, prévient le membre en MP et enregistre l'action |
|
| `/warn` | `user`, `reason` (obligatoires) | Modérer les membres | ✅ | Avertit, prévient le membre en MP et enregistre l'action |
|
||||||
| `/mute` | `user`, `minutes` (1–40320), `reason` | Modérer les membres | ✅ | Timeout temporaire (28 j max) + notification en MP |
|
| `/mute` | `user`, `minutes` (1–40320), `reason` | Modérer les membres | ✅ | Timeout temporaire (28 j max) + notification en MP |
|
||||||
|
| `/unmute` | `user`, `reason` | Modérer les membres | ✅ | Lève le timeout avant l’échéance (message clair si la personne n’est pas en exclusion) |
|
||||||
|
| `/unban` | `user`, `reason` | Bannir | ✅ | Lève le bannissement, même si la personne a déjà quitté, et la prévient en MP |
|
||||||
| `/kick` | `user`, `reason` | Expulser | ✅ | Expulse du serveur et journalise l'action |
|
| `/kick` | `user`, `reason` | Expulser | ✅ | Expulse du serveur et journalise l'action |
|
||||||
| `/ban` | `user`, `reason`, `delete_days` (0–7) | Bannir | ✅ | Bannit (même si le membre a déjà quitté), purge optionnelle des messages |
|
| `/ban` | `user`, `reason`, `delete_days` (0–7) | Bannir | ✅ | Bannit (même si le membre a déjà quitté), purge optionnelle des messages |
|
||||||
| `/clear` | `amount` (1–100) | Gérer les messages | ✅ | Supprime les N derniers messages (ceux de plus de 14 j sont ignorés) |
|
| `/clear` | `amount` (1–100) | Gérer les messages | ✅ | Supprime les N derniers messages (ceux de plus de 14 j sont ignorés) |
|
||||||
|
|||||||
@@ -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'}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.`,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
|
import { ACCESS_LEVELS } from '../../config/constants.js';
|
||||||
|
import { UserFacingError } from '../../core/errors.js';
|
||||||
|
import {
|
||||||
|
assertModerationTarget,
|
||||||
|
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('unban')
|
||||||
|
.setDescription('Lever le bannissement d’un membre')
|
||||||
|
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
|
||||||
|
.addUserOption((option) => option.setName('user').setDescription('Membre').setRequired(true))
|
||||||
|
.addStringOption((option) => option.setName('reason').setDescription('Motif').setMaxLength(500));
|
||||||
|
|
||||||
|
/** Counterpart of `/ban`, usable whether or not the member already left. */
|
||||||
|
export async function execute(interaction) {
|
||||||
|
const user = interaction.options.getUser('user', true);
|
||||||
|
const reason = interaction.options.getString('reason');
|
||||||
|
|
||||||
|
// Fetching the ban first turns “not banned” into a clear message instead of
|
||||||
|
// the missing-ban error Discord returns from the removal itself.
|
||||||
|
const ban = await interaction.guild.bans.fetch(user.id).catch(() => null);
|
||||||
|
if (!ban) {
|
||||||
|
throw new UserFacingError(`${user.tag} n’est pas banni de ce serveur : il n’y a rien à lever.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// A banned member has usually already left, so the hierarchy is only checked
|
||||||
|
// while they are still on the server (a ban applied too quickly, typically).
|
||||||
|
const member = await interaction.guild.members.fetch(user.id).catch(() => null);
|
||||||
|
if (member) assertModerationTarget(interaction, member);
|
||||||
|
|
||||||
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
await interaction.guild.bans.remove(
|
||||||
|
user.id,
|
||||||
|
reason ?? `Débannissement demandé par ${interaction.user.tag}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await logModerationAction(interaction, { action: 'unban', targetId: user.id, reason });
|
||||||
|
// A direct message is the only way to tell someone they may come back.
|
||||||
|
const recipient = member ?? (await interaction.client.users.fetch(user.id).catch(() => null));
|
||||||
|
if (recipient) {
|
||||||
|
await notifyTarget(
|
||||||
|
recipient,
|
||||||
|
{ embeds: [targetNoticeEmbed({ action: 'unban', guildName: interaction.guild.name, reason })] },
|
||||||
|
interaction.guildId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
successEmbed(
|
||||||
|
`C’est fait : **${user.tag}** peut de nouveau rejoindre le serveur. L’historique reste consultable avec \`/mod logs\`.`,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
|
import { ACCESS_LEVELS } from '../../config/constants.js';
|
||||||
|
import { UserFacingError } from '../../core/errors.js';
|
||||||
|
import {
|
||||||
|
assertModerationTarget,
|
||||||
|
fetchTargetMember,
|
||||||
|
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('unmute')
|
||||||
|
.setDescription('Lever l’exclusion temporaire d’un membre avant la fin')
|
||||||
|
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
|
||||||
|
.addUserOption((option) => option.setName('user').setDescription('Membre').setRequired(true))
|
||||||
|
.addStringOption((option) => option.setName('reason').setDescription('Motif').setMaxLength(500));
|
||||||
|
|
||||||
|
/** Counterpart of `/mute`: clears the timeout early and keeps the trail. */
|
||||||
|
export async function execute(interaction) {
|
||||||
|
const user = interaction.options.getUser('user', true);
|
||||||
|
const reason = interaction.options.getString('reason');
|
||||||
|
|
||||||
|
const target = await fetchTargetMember(interaction, user.id);
|
||||||
|
assertModerationTarget(interaction, target);
|
||||||
|
// Discord answers a timeout removal on a member who is not muted with an
|
||||||
|
// opaque error, so the check turns it into an explicit message.
|
||||||
|
if (!target.isCommunicationDisabled()) {
|
||||||
|
throw new UserFacingError(
|
||||||
|
`${target.user.tag} n’est pas en exclusion temporaire : cette personne peut déjà écrire.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||||
|
await target.timeout(null, reason ?? `Levée d’exclusion demandée par ${interaction.user.tag}`);
|
||||||
|
|
||||||
|
await logModerationAction(interaction, { action: 'unmute', targetId: target.id, reason });
|
||||||
|
await notifyTarget(target, {
|
||||||
|
embeds: [targetNoticeEmbed({ action: 'unmute', guildName: interaction.guild.name, reason })],
|
||||||
|
});
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [
|
||||||
|
successEmbed(
|
||||||
|
`C’est fait : **${target.user.tag}** peut de nouveau écrire sur le serveur. L’historique reste consultable avec \`/mod logs\`.`,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
+19
-7
@@ -28,14 +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 },
|
||||||
kick: { label: 'Expulsion', color: COLORS.moderation, duration: false },
|
unmute: {
|
||||||
ban: { label: 'Bannissement', color: COLORS.error, duration: false },
|
label: 'Levée de la mise en sourdine',
|
||||||
clear: { label: 'Suppression de messages', color: COLORS.warning, duration: false },
|
emoji: '🔊',
|
||||||
role: { label: 'Modification de rôle', color: COLORS.primary, duration: false },
|
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). */
|
/** Ticket categories and who can see them (M0-T05 / M6-T01). */
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
-- Lifted sanctions join the sanctions in the moderation history
|
||||||
|
--
|
||||||
|
-- `/unmute` and `/unban` are recorded like `/mute` and `/ban`, but SQLite cannot
|
||||||
|
-- alter a CHECK constraint: the table is rebuilt and the rows copied over so the
|
||||||
|
-- history already stored survives the migration.
|
||||||
|
|
||||||
|
CREATE TABLE moderation_actions_lifted (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
guild_id TEXT NOT NULL,
|
||||||
|
action TEXT NOT NULL CHECK (action IN ('warn', 'mute', 'unmute', 'kick', 'ban', 'unban', 'clear', 'role')),
|
||||||
|
target_id TEXT,
|
||||||
|
moderator_id TEXT NOT NULL,
|
||||||
|
reason TEXT,
|
||||||
|
duration_ms INTEGER,
|
||||||
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO moderation_actions_lifted (id, guild_id, action, target_id, moderator_id, reason, duration_ms, created_at)
|
||||||
|
SELECT id, guild_id, action, target_id, moderator_id, reason, duration_ms, created_at FROM moderation_actions;
|
||||||
|
|
||||||
|
DROP TABLE moderation_actions;
|
||||||
|
ALTER TABLE moderation_actions_lifted RENAME TO moderation_actions;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_moderation_target ON moderation_actions (guild_id, target_id);
|
||||||
@@ -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 },
|
||||||
@@ -100,9 +111,11 @@ export async function sendModerationLog(
|
|||||||
* Sends the private notice to the sanctioned member, when the server wants one
|
* Sends the private notice to the sanctioned member, when the server wants one
|
||||||
* (M8-T07). Never throws: plenty of accounts refuse direct messages, and that
|
* (M8-T07). Never throws: plenty of accounts refuse direct messages, and that
|
||||||
* must not turn a successful sanction into an error.
|
* must not turn a successful sanction into an error.
|
||||||
|
* @param guildId Server the sanction belongs to. A lifted ban targets someone
|
||||||
|
* who has left the server, so a plain `User` is accepted with an explicit id.
|
||||||
*/
|
*/
|
||||||
export async function notifyTarget(member, payload) {
|
export async function notifyTarget(member, payload, guildId = member.guild?.id) {
|
||||||
if (!readSetting('moderation.dmTarget', member.guild.id)) return false;
|
if (!readSetting('moderation.dmTarget', guildId)) return false;
|
||||||
return member
|
return member
|
||||||
.send(payload)
|
.send(payload)
|
||||||
.then(() => true)
|
.then(() => true)
|
||||||
@@ -115,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) });
|
||||||
|
|||||||
@@ -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 },
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { after, before, describe, it } from 'node:test';
|
import { after, before, describe, it } from 'node:test';
|
||||||
import { closeDatabase, getDatabase, initDatabase } from '../src/database/index.js';
|
import { closeDatabase, getDatabase, initDatabase } from '../src/database/index.js';
|
||||||
|
import { listActions, recordAction } from '../src/database/repositories/moderation-repository.js';
|
||||||
import { getSetting, setSetting } from '../src/database/repositories/settings-repository.js';
|
import { getSetting, setSetting } from '../src/database/repositories/settings-repository.js';
|
||||||
|
|
||||||
describe('database', () => {
|
describe('database', () => {
|
||||||
@@ -22,6 +23,20 @@ describe('database', () => {
|
|||||||
assert.equal(getSetting('guild-b', 'welcome'), null);
|
assert.equal(getSetting('guild-b', 'welcome'), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('records a lifted sanction next to the sanction it lifts', () => {
|
||||||
|
// `/unmute` and `/unban` go through the same CHECK constraint as `/mute`
|
||||||
|
// and `/ban`, so a migration that forgets them breaks the history.
|
||||||
|
for (const action of ['unban', 'unmute']) {
|
||||||
|
recordAction({ guildId: 'g', action, moderatorId: 'mod', targetId: 'u', reason: 'Erreur' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows = listActions({ guildId: 'g', targetId: 'u' });
|
||||||
|
assert.deepEqual(
|
||||||
|
rows.map((row) => row.action).sort(),
|
||||||
|
['unban', 'unmute'],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('prevents two open tickets for the same author and category', () => {
|
it('prevents two open tickets for the same author and category', () => {
|
||||||
const insert = getDatabase().prepare(
|
const insert = getDatabase().prepare(
|
||||||
"INSERT INTO tickets (guild_id, category_id, author_id) VALUES ('g', 'bug', 'u')",
|
"INSERT INTO tickets (guild_id, category_id, author_id) VALUES ('g', 'bug', 'u')",
|
||||||
|
|||||||
@@ -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'));
|
||||||
|
|||||||
Reference in new issue
Block a user