feat(core): add shared constants, interaction components and Gitea client helpers

Moderation, tickets, polls and Gitea events reuse the same labels, colours and buttons; normalising list responses in the client keeps both commands and webhooks free of version quirks.
This commit is contained in:
BlackAngelTV committed 2026-09-15 14:50:34 +02:00
1 parent 03a217c775
commit 66be463ba3
4 files changed
+77 -6

No files matched your search

+39
View File
@@ -1,5 +1,13 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } 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
@@ -9,3 +17,34 @@ export function linkButtons(links) {
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),
),
];
}
/** 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;
}
-6
View File
@@ -17,9 +17,3 @@ export function successEmbed(description) {
export function errorEmbed(description) {
return baseEmbed(COLORS.error).setTitle('Erreur').setDescription(description);
}
export function notImplementedEmbed(feature) {
return baseEmbed(COLORS.warning)
.setTitle('Bientôt disponible')
.setDescription(`La fonctionnalité **${feature}** n'est pas encore implémentée.`);
}