refactor(all): uniformisation
This commit is contained in:
89 files changed
+10215
-10215
No files matched your search
+99
-99
@@ -1,99 +1,99 @@
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, UserSelectMenuBuilder } from 'discord.js';
|
||||
|
||||
/** Discord label and custom id limits. */
|
||||
const LABEL_MAX = 80;
|
||||
export const POLL_CHOICES_MAX = 10;
|
||||
|
||||
function truncate(text, max) {
|
||||
return text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
||||
}
|
||||
|
||||
/** Builds a row of link buttons, skipping links without a URL (M12-T03). */
|
||||
export function linkButtons(links) {
|
||||
const buttons = links
|
||||
.filter((link) => link.url)
|
||||
.slice(0, 5)
|
||||
.map((link) => new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel(link.label).setURL(link.url));
|
||||
|
||||
return buttons.length > 0 ? [new ActionRowBuilder().addComponents(buttons)] : [];
|
||||
}
|
||||
|
||||
/** Claim / close controls posted in a ticket channel (M6-T05 / M6-T06). */
|
||||
export function ticketButtons() {
|
||||
return [
|
||||
new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('ticket:claim')
|
||||
.setLabel('Prendre en charge')
|
||||
.setStyle(ButtonStyle.Primary),
|
||||
new ButtonBuilder().setCustomId('ticket:close').setLabel('Fermer').setStyle(ButtonStyle.Danger),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Control panel posted in a temporary voice channel (M14-T05):
|
||||
* buttons for the whole channel, select menus for a specific member.
|
||||
*/
|
||||
export function voicePanelComponents({ locked = false } = {}) {
|
||||
return [
|
||||
new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('voice:rename')
|
||||
.setLabel('Renommer')
|
||||
.setEmoji('✏️')
|
||||
.setStyle(ButtonStyle.Secondary),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('voice:limit')
|
||||
.setLabel('Limiter')
|
||||
.setEmoji('👥')
|
||||
.setStyle(ButtonStyle.Secondary),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('voice:lock')
|
||||
.setLabel(locked ? 'Déverrouiller' : 'Verrouiller')
|
||||
.setEmoji(locked ? '🔓' : '🔒')
|
||||
.setStyle(locked ? ButtonStyle.Success : ButtonStyle.Secondary),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('voice:claim')
|
||||
.setLabel('Réclamer')
|
||||
.setEmoji('👑')
|
||||
.setStyle(ButtonStyle.Primary),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('voice:delete')
|
||||
.setLabel('Supprimer')
|
||||
.setEmoji('🗑️')
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
),
|
||||
memberSelect('voice:permit', 'Autoriser un membre à rejoindre...'),
|
||||
memberSelect('voice:kick', 'Exclure un membre du salon...'),
|
||||
memberSelect('voice:transfer', 'Transférer la propriété du salon...'),
|
||||
];
|
||||
}
|
||||
|
||||
function memberSelect(customId, placeholder) {
|
||||
return new ActionRowBuilder().addComponents(
|
||||
new UserSelectMenuBuilder()
|
||||
.setCustomId(customId)
|
||||
.setPlaceholder(placeholder)
|
||||
.setMinValues(1)
|
||||
.setMaxValues(1),
|
||||
);
|
||||
}
|
||||
|
||||
/** One button per choice, 5 per row at most (M10-T02). */
|
||||
export function pollButtons(pollId, choices) {
|
||||
const rows = [];
|
||||
for (let start = 0; start < Math.min(choices.length, POLL_CHOICES_MAX); start += 5) {
|
||||
rows.push(
|
||||
new ActionRowBuilder().addComponents(
|
||||
choices.slice(start, start + 5).map((choice, offset) =>
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`poll:${pollId}:${start + offset}`)
|
||||
.setLabel(truncate(choice, LABEL_MAX))
|
||||
.setStyle(ButtonStyle.Secondary),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, UserSelectMenuBuilder } from 'discord.js';
|
||||
|
||||
/** Discord label and custom id limits. */
|
||||
const LABEL_MAX = 80;
|
||||
export const POLL_CHOICES_MAX = 10;
|
||||
|
||||
function truncate(text, max) {
|
||||
return text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
||||
}
|
||||
|
||||
/** Builds a row of link buttons, skipping links without a URL (M12-T03). */
|
||||
export function linkButtons(links) {
|
||||
const buttons = links
|
||||
.filter((link) => link.url)
|
||||
.slice(0, 5)
|
||||
.map((link) => new ButtonBuilder().setStyle(ButtonStyle.Link).setLabel(link.label).setURL(link.url));
|
||||
|
||||
return buttons.length > 0 ? [new ActionRowBuilder().addComponents(buttons)] : [];
|
||||
}
|
||||
|
||||
/** Claim / close controls posted in a ticket channel (M6-T05 / M6-T06). */
|
||||
export function ticketButtons() {
|
||||
return [
|
||||
new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('ticket:claim')
|
||||
.setLabel('Prendre en charge')
|
||||
.setStyle(ButtonStyle.Primary),
|
||||
new ButtonBuilder().setCustomId('ticket:close').setLabel('Fermer').setStyle(ButtonStyle.Danger),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Control panel posted in a temporary voice channel (M14-T05):
|
||||
* buttons for the whole channel, select menus for a specific member.
|
||||
*/
|
||||
export function voicePanelComponents({ locked = false } = {}) {
|
||||
return [
|
||||
new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('voice:rename')
|
||||
.setLabel('Renommer')
|
||||
.setEmoji('✏️')
|
||||
.setStyle(ButtonStyle.Secondary),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('voice:limit')
|
||||
.setLabel('Limiter')
|
||||
.setEmoji('👥')
|
||||
.setStyle(ButtonStyle.Secondary),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('voice:lock')
|
||||
.setLabel(locked ? 'Déverrouiller' : 'Verrouiller')
|
||||
.setEmoji(locked ? '🔓' : '🔒')
|
||||
.setStyle(locked ? ButtonStyle.Success : ButtonStyle.Secondary),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('voice:claim')
|
||||
.setLabel('Réclamer')
|
||||
.setEmoji('👑')
|
||||
.setStyle(ButtonStyle.Primary),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('voice:delete')
|
||||
.setLabel('Supprimer')
|
||||
.setEmoji('🗑️')
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
),
|
||||
memberSelect('voice:permit', 'Autoriser un membre à rejoindre...'),
|
||||
memberSelect('voice:kick', 'Exclure un membre du salon...'),
|
||||
memberSelect('voice:transfer', 'Transférer la propriété du salon...'),
|
||||
];
|
||||
}
|
||||
|
||||
function memberSelect(customId, placeholder) {
|
||||
return new ActionRowBuilder().addComponents(
|
||||
new UserSelectMenuBuilder()
|
||||
.setCustomId(customId)
|
||||
.setPlaceholder(placeholder)
|
||||
.setMinValues(1)
|
||||
.setMaxValues(1),
|
||||
);
|
||||
}
|
||||
|
||||
/** One button per choice, 5 per row at most (M10-T02). */
|
||||
export function pollButtons(pollId, choices) {
|
||||
const rows = [];
|
||||
for (let start = 0; start < Math.min(choices.length, POLL_CHOICES_MAX); start += 5) {
|
||||
rows.push(
|
||||
new ActionRowBuilder().addComponents(
|
||||
choices.slice(start, start + 5).map((choice, offset) =>
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`poll:${pollId}:${start + offset}`)
|
||||
.setLabel(truncate(choice, LABEL_MAX))
|
||||
.setStyle(ButtonStyle.Secondary),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
+55
-55
@@ -1,55 +1,55 @@
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
import { BOT_NAME, COLORS } from '../config/constants.js';
|
||||
|
||||
/**
|
||||
* Bot voice — one tone everywhere (M12-T02). Every user-facing string in the project follows
|
||||
* these rules, so the messages stay consistent as commands are added:
|
||||
*
|
||||
* - Informal French, short sentences, active voice; never a reproach or irony.
|
||||
* - The title states the outcome, the description says what to do next.
|
||||
* - One emoji per title, never decorative inside the body.
|
||||
* - No gendered agreement on a person: "tu es propriétaire", "ce membre", "l'équipe",
|
||||
* "la personne" — never "il / elle", "cher / chère", "ravi·e".
|
||||
* - An error explains the cause, recalls the rule and offers the way out.
|
||||
* - Same vocabulary across modules: équipe, membre, salon, ticket, motif.
|
||||
*/
|
||||
export const TONE = Object.freeze({
|
||||
success: '✅ C’est fait',
|
||||
error: '❌ Oups',
|
||||
warning: '⚠️ Attention',
|
||||
advice: '💡 Bon à savoir',
|
||||
});
|
||||
|
||||
/** Base embed with the shared FWS-Bot visual identity (M12-T02). */
|
||||
export function baseEmbed(color = COLORS.primary) {
|
||||
return new EmbedBuilder().setColor(color).setFooter({ text: BOT_NAME }).setTimestamp();
|
||||
}
|
||||
|
||||
export function infoEmbed(title, description) {
|
||||
return baseEmbed(COLORS.info).setTitle(title).setDescription(description);
|
||||
}
|
||||
|
||||
export function successEmbed(description, { title = TONE.success } = {}) {
|
||||
return baseEmbed(COLORS.success).setTitle(title).setDescription(description);
|
||||
}
|
||||
|
||||
export function warningEmbed(description, { title = TONE.warning } = {}) {
|
||||
return baseEmbed(COLORS.warning).setTitle(title).setDescription(description);
|
||||
}
|
||||
|
||||
export function errorEmbed(description, { title = TONE.error } = {}) {
|
||||
return baseEmbed(COLORS.error).setTitle(title).setDescription(description);
|
||||
}
|
||||
|
||||
/** Uniform list marker, so every embed lists things the same way. */
|
||||
export function bullets(lines) {
|
||||
return lines
|
||||
.filter(Boolean)
|
||||
.map((line) => `• ${line}`)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
/** Adds the "what you can do now" line that most replies end with. */
|
||||
export function withHint(description, hint) {
|
||||
return hint ? `${description}\n\n${hint}` : description;
|
||||
}
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
import { BOT_NAME, COLORS } from '../config/constants.js';
|
||||
|
||||
/**
|
||||
* Bot voice — one tone everywhere (M12-T02). Every user-facing string in the project follows
|
||||
* these rules, so the messages stay consistent as commands are added:
|
||||
*
|
||||
* - Informal French, short sentences, active voice; never a reproach or irony.
|
||||
* - The title states the outcome, the description says what to do next.
|
||||
* - One emoji per title, never decorative inside the body.
|
||||
* - No gendered agreement on a person: "tu es propriétaire", "ce membre", "l'équipe",
|
||||
* "la personne" — never "il / elle", "cher / chère", "ravi·e".
|
||||
* - An error explains the cause, recalls the rule and offers the way out.
|
||||
* - Same vocabulary across modules: équipe, membre, salon, ticket, motif.
|
||||
*/
|
||||
export const TONE = Object.freeze({
|
||||
success: '✅ C’est fait',
|
||||
error: '❌ Oups',
|
||||
warning: '⚠️ Attention',
|
||||
advice: '💡 Bon à savoir',
|
||||
});
|
||||
|
||||
/** Base embed with the shared FWS-Bot visual identity (M12-T02). */
|
||||
export function baseEmbed(color = COLORS.primary) {
|
||||
return new EmbedBuilder().setColor(color).setFooter({ text: BOT_NAME }).setTimestamp();
|
||||
}
|
||||
|
||||
export function infoEmbed(title, description) {
|
||||
return baseEmbed(COLORS.info).setTitle(title).setDescription(description);
|
||||
}
|
||||
|
||||
export function successEmbed(description, { title = TONE.success } = {}) {
|
||||
return baseEmbed(COLORS.success).setTitle(title).setDescription(description);
|
||||
}
|
||||
|
||||
export function warningEmbed(description, { title = TONE.warning } = {}) {
|
||||
return baseEmbed(COLORS.warning).setTitle(title).setDescription(description);
|
||||
}
|
||||
|
||||
export function errorEmbed(description, { title = TONE.error } = {}) {
|
||||
return baseEmbed(COLORS.error).setTitle(title).setDescription(description);
|
||||
}
|
||||
|
||||
/** Uniform list marker, so every embed lists things the same way. */
|
||||
export function bullets(lines) {
|
||||
return lines
|
||||
.filter(Boolean)
|
||||
.map((line) => `• ${line}`)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
/** Adds the "what you can do now" line that most replies end with. */
|
||||
export function withHint(description, hint) {
|
||||
return hint ? `${description}\n\n${hint}` : description;
|
||||
}
|
||||
Reference in new issue
Block a user