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

+20
View File
@@ -20,6 +20,16 @@ export const ACCESS_LEVELS = Object.freeze({
OWNER: 3,
});
/** Moderation actions: Discord label, embed color and stored duration (M8). */
export const MODERATION_ACTIONS = Object.freeze({
warn: { label: 'Avertissement', color: COLORS.warning, duration: false },
mute: { label: 'Exclusion temporaire', color: COLORS.moderation, duration: true },
kick: { label: 'Expulsion', color: COLORS.moderation, duration: false },
ban: { label: 'Bannissement', color: COLORS.error, duration: false },
clear: { label: 'Suppression de messages', color: COLORS.warning, duration: false },
role: { label: 'Modification de rôle', color: COLORS.primary, duration: false },
});
/** Ticket categories and who can see them (M0-T05 / M6-T01). */
export const TICKET_CATEGORIES = Object.freeze([
{ id: 'support', label: 'Support utilisateur', scope: ['staff', 'owner'] },
@@ -29,6 +39,16 @@ export const TICKET_CATEGORIES = Object.freeze([
{ id: 'internal', label: 'Demande interne', scope: ['owner'] },
]);
/** Gitea webhook event -> notification type (M9-T03). */
export const GITEA_EVENT_TYPES = Object.freeze({
issues: 'issues',
pull_request: 'pull_request',
push: 'push',
create: 'push',
delete: 'push',
release: 'release',
});
export const NOTIFICATION_TYPES = Object.freeze([
'issues',
'pull_requests',
+18
View File
@@ -34,6 +34,22 @@ export async function giteaRequest(endpoint, { method = 'GET', body } = {}) {
);
}
/** True when both the Gitea URL and token are configured (M5-T01). */
export function isGiteaConfigured() {
return Boolean(env.gitea.url && env.gitea.token);
}
/** Gitea returns either a bare array or a `{ data: [...] }` wrapper depending on the version. */
export function asList(payload) {
if (Array.isArray(payload)) return payload;
return Array.isArray(payload?.data) ? payload.data : [];
}
/** Human readable URL of the configured repository, used in embeds. */
export function repositoryUrl() {
return env.gitea.url ? `${env.gitea.url}/${env.gitea.owner}/${env.gitea.repo}` : '';
}
const repoPath = () => `/repos/${env.gitea.owner}/${env.gitea.repo}`;
export const gitea = {
@@ -48,4 +64,6 @@ export const gitea = {
listCommits: (limit = 10) => giteaRequest(`${repoPath()}/commits?limit=${limit}`),
listReleases: (limit = 5) => giteaRequest(`${repoPath()}/releases?limit=${limit}`),
getLatestRelease: () => giteaRequest(`${repoPath()}/releases/latest`),
getReleaseByTag: (tag) => giteaRequest(`${repoPath()}/releases/tags/${encodeURIComponent(tag)}`),
listBranches: (limit = 20) => giteaRequest(`${repoPath()}/branches?limit=${limit}`),
};
+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.`);
}