palico-bot/src/commands/game/maketeam.js
Shinuwa 3795ee06cb Add file headers, tidy the stylesheet and document the conventions
Headers:
- Every JavaScript file (sources, front, scripts, tests) starts with a
  /** @file … */ header, in the three levels used by sokko-g: a short
  description for simple files; Utilisé par / Attention / @see for
  shared modules; a full header (context, entry points, callers,
  dependencies, pitfalls) for index.js, the music queue, the web
  server, the storage manager and the jukebox page script.
- No @author, @version or @since: git already knows.
- test/fileHeaders.test.js fails `npm run check` when a header is
  missing or a central file's header is incomplete.

Stylesheet (no visual change, checked by comparing every element's
computed styles in Chromium at 1280, 800 and 400 px, hover included):
- Role header and section comments.
- Transparent shades derive from the colour variables with
  color-mix() instead of copied rgba() values; new tokens for repeated
  values (text, text on accent, accent gradient, white veils, shadow).
- Native nesting for buttons, the live indicator, upload rows and
  home cards; drop the unused .hero__visual--large and redundant rules.
- Utility classes move to the end so they win over components. The
  library list's u-mt-1, which never applied (.list reset it), is
  removed to keep the layout as it was.

Docs: CONTRIBUTING.md describes the language, header and stylesheet
conventions; CLAUDE.md points to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 21:05:59 +01:00

65 lines
2.1 KiB
JavaScript

/**
* @file Commande /maketeam : répartit une liste de joueurs au hasard en équipes. Les noms sont séparés
* par des espaces, ou seulement par des virgules dès qu'il y en a une.
*/
import { MessageFlags, SlashCommandBuilder } from "discord.js";
import { shuffle } from "../../features/utilities.js";
// « Alice Bob » ou « Jean Pierre, Marie » : dès qu'il y a une virgule, seules les virgules
// séparent les joueurs.
function parsePlayers(input) {
const separator = input.includes(",") ? "," : /\s+/;
return input
.split(separator)
.map((player) => player.trim())
.filter(Boolean);
}
const command = {
data: new SlashCommandBuilder()
.setName("maketeam")
.setDescription("Crée des équipes au hasard")
.addIntegerOption((option) =>
option
.setName("number")
.setDescription("Nombre d'équipes")
.setMinValue(1)
.setMaxValue(20)
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("players")
.setDescription("Joueurs séparés par des espaces, ou par des virgules si un nom contient un espace")
.setMinLength(1)
.setMaxLength(1000)
.setRequired(true)
),
async execute(interaction) {
const teamNumber = interaction.options.getInteger("number");
const players = interaction.options.getString("players");
const playersArray = parsePlayers(players);
if (playersArray.length === 0 || teamNumber > playersArray.length) {
await interaction.reply({
content: "Le nombre d'équipes ne peut pas dépasser le nombre de joueurs.",
flags: MessageFlags.Ephemeral,
});
return;
}
const teams = Array.from({ length: teamNumber }, () => []);
shuffle(playersArray).forEach((player, index) => {
const teamIndex = index % teamNumber;
teams[teamIndex].push(player);
});
const teamList = teams
.map((team, index) => `${index + 1}. ${team.join(", ")}`)
.join("\n");
await interaction.reply(`Yop ! Voici les équipes proposées :\n\n${teamList}`);
},
};
export { command, parsePlayers };