refactor(all): uniformisation

This commit is contained in:
BlackAngelTV committed 2026-09-23 18:25:28 +02:00
1 parent ee538cb943
commit 50665c8edd
89 files changed
+10215 -10215

No files matched your search

+68 -68
View File
@@ -1,68 +1,68 @@
export const BOT_NAME = 'FWS-Bot';
/** Embed colors by category (M12-T01). */
export const COLORS = Object.freeze({
primary: 0x1793d1,
success: 0x2ecc71,
warning: 0xf1c40f,
error: 0xe74c3c,
info: 0x3498db,
gitea: 0x609926,
moderation: 0xe67e22,
ticket: 0x9b59b6,
});
/** Ordered from least to most privileged (M3-T01). */
export const ACCESS_LEVELS = Object.freeze({
USER: 0,
STAFF: 1,
DEV: 2,
OWNER: 3,
});
/** Same names for the same levels in every message (M12-T02). */
export const ACCESS_LABELS = Object.freeze({
[ACCESS_LEVELS.USER]: 'Membre',
[ACCESS_LEVELS.STAFF]: 'Staff',
[ACCESS_LEVELS.DEV]: 'Dev',
[ACCESS_LEVELS.OWNER]: 'Owner',
});
/** 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: 'Aide et support', scope: ['staff', 'owner'] },
{ id: 'bug', label: 'Bug', scope: ['staff', 'dev', 'owner'] },
{ id: 'dev-question', label: 'Question de développement', scope: ['dev', 'owner'] },
{ id: 'report', label: 'Signalement', scope: ['staff', 'owner'] },
{ 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',
'commits',
'releases',
'announcements',
'errors',
'community',
]);
export const BOT_NAME = 'FWS-Bot';
/** Embed colors by category (M12-T01). */
export const COLORS = Object.freeze({
primary: 0x1793d1,
success: 0x2ecc71,
warning: 0xf1c40f,
error: 0xe74c3c,
info: 0x3498db,
gitea: 0x609926,
moderation: 0xe67e22,
ticket: 0x9b59b6,
});
/** Ordered from least to most privileged (M3-T01). */
export const ACCESS_LEVELS = Object.freeze({
USER: 0,
STAFF: 1,
DEV: 2,
OWNER: 3,
});
/** Same names for the same levels in every message (M12-T02). */
export const ACCESS_LABELS = Object.freeze({
[ACCESS_LEVELS.USER]: 'Membre',
[ACCESS_LEVELS.STAFF]: 'Staff',
[ACCESS_LEVELS.DEV]: 'Dev',
[ACCESS_LEVELS.OWNER]: 'Owner',
});
/** 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: 'Aide et support', scope: ['staff', 'owner'] },
{ id: 'bug', label: 'Bug', scope: ['staff', 'dev', 'owner'] },
{ id: 'dev-question', label: 'Question de développement', scope: ['dev', 'owner'] },
{ id: 'report', label: 'Signalement', scope: ['staff', 'owner'] },
{ 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',
'commits',
'releases',
'announcements',
'errors',
'community',
]);
+103 -103
View File
@@ -1,103 +1,103 @@
import { existsSync } from 'node:fs';
if (existsSync('.env')) {
process.loadEnvFile('.env');
}
const read = (key, fallback = '') => process.env[key]?.trim() || fallback;
const readInt = (key, fallback) => Number.parseInt(read(key), 10) || fallback;
const readBool = (key, fallback = false) => {
const value = read(key);
return value === '' ? fallback : value === 'true';
};
/** Durations accept 0, which `readInt` cannot express because 0 is falsy. */
const readDuration = (key, fallback) => {
const value = read(key);
if (value === '') return fallback;
const parsed = Number.parseInt(value, 10);
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
};
export const env = Object.freeze({
nodeEnv: read('NODE_ENV', 'development'),
logLevel: read('LOG_LEVEL', 'info'),
logDir: read('LOG_DIR', './logs'),
logRetentionDays: readInt('LOG_RETENTION_DAYS', 30),
discord: {
token: read('DISCORD_TOKEN'),
clientId: read('DISCORD_CLIENT_ID'),
guildId: read('DISCORD_GUILD_ID'),
},
roles: {
owner: read('ROLE_OWNER_ID'),
dev: read('ROLE_DEV_ID'),
staff: read('ROLE_STAFF_ID'),
member: read('ROLE_MEMBER_ID'),
},
channels: {
welcome: read('CHANNEL_WELCOME_ID'),
rules: read('CHANNEL_RULES_ID'),
announcements: read('CHANNEL_ANNOUNCEMENTS_ID'),
logs: read('CHANNEL_LOGS_ID'),
modLogs: read('CHANNEL_MOD_LOGS_ID'),
ticketLogs: read('CHANNEL_TICKETS_LOGS_ID'),
notifIssues: read('CHANNEL_NOTIF_ISSUES_ID'),
notifPullRequests: read('CHANNEL_NOTIF_PULL_REQUESTS_ID'),
notifCommits: read('CHANNEL_NOTIF_COMMITS_ID'),
notifReleases: read('CHANNEL_NOTIF_RELEASES_ID'),
notifErrors: read('CHANNEL_NOTIF_ERRORS_ID'),
ticketCategory: read('CATEGORY_TICKETS_ID'),
voiceTrigger: read('CHANNEL_VOICE_TRIGGER_ID'),
voiceCategory: read('CATEGORY_VOICE_ID'),
},
voice: {
emptyGraceMs: readDuration('VOICE_EMPTY_GRACE_MS', 5_000),
},
bot: {
statusIntervalSeconds: readDuration('BOT_STATUS_INTERVAL_SECONDS', 60),
},
gitea: {
url: read('GITEA_URL').replace(/\/+$/, ''),
token: read('GITEA_TOKEN'),
owner: read('GITEA_OWNER'),
repo: read('GITEA_REPO'),
timeoutMs: readInt('GITEA_TIMEOUT_MS', 10_000),
maxRetries: readInt('GITEA_MAX_RETRIES', 2),
},
webhook: {
enabled: readBool('WEBHOOK_ENABLED'),
host: read('WEBHOOK_HOST', '0.0.0.0'),
port: readInt('WEBHOOK_PORT', 3000),
path: read('WEBHOOK_PATH', '/webhooks/gitea'),
secret: read('GITEA_WEBHOOK_SECRET'),
},
database: {
path: read('DATABASE_PATH', './data/fws-bot.sqlite'),
backupDir: read('BACKUP_DIR', './data/backups'),
},
links: {
website: read('FWS_WEBSITE_URL'),
docs: read('FWS_DOCS_URL'),
discordInvite: read('FWS_DISCORD_INVITE_URL'),
archRepo: read('FWS_ARCH_REPO_URL'),
},
});
/** Values that must never appear in Discord messages or logs. */
export const secrets = [env.discord.token, env.gitea.token, env.webhook.secret].filter(Boolean);
export function assertRequiredEnv(keys) {
const missing = keys.filter((key) => !read(key));
if (missing.length > 0) {
throw new Error(`Missing required environment variables: ${missing.join(', ')}`);
}
}
import { existsSync } from 'node:fs';
if (existsSync('.env')) {
process.loadEnvFile('.env');
}
const read = (key, fallback = '') => process.env[key]?.trim() || fallback;
const readInt = (key, fallback) => Number.parseInt(read(key), 10) || fallback;
const readBool = (key, fallback = false) => {
const value = read(key);
return value === '' ? fallback : value === 'true';
};
/** Durations accept 0, which `readInt` cannot express because 0 is falsy. */
const readDuration = (key, fallback) => {
const value = read(key);
if (value === '') return fallback;
const parsed = Number.parseInt(value, 10);
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
};
export const env = Object.freeze({
nodeEnv: read('NODE_ENV', 'development'),
logLevel: read('LOG_LEVEL', 'info'),
logDir: read('LOG_DIR', './logs'),
logRetentionDays: readInt('LOG_RETENTION_DAYS', 30),
discord: {
token: read('DISCORD_TOKEN'),
clientId: read('DISCORD_CLIENT_ID'),
guildId: read('DISCORD_GUILD_ID'),
},
roles: {
owner: read('ROLE_OWNER_ID'),
dev: read('ROLE_DEV_ID'),
staff: read('ROLE_STAFF_ID'),
member: read('ROLE_MEMBER_ID'),
},
channels: {
welcome: read('CHANNEL_WELCOME_ID'),
rules: read('CHANNEL_RULES_ID'),
announcements: read('CHANNEL_ANNOUNCEMENTS_ID'),
logs: read('CHANNEL_LOGS_ID'),
modLogs: read('CHANNEL_MOD_LOGS_ID'),
ticketLogs: read('CHANNEL_TICKETS_LOGS_ID'),
notifIssues: read('CHANNEL_NOTIF_ISSUES_ID'),
notifPullRequests: read('CHANNEL_NOTIF_PULL_REQUESTS_ID'),
notifCommits: read('CHANNEL_NOTIF_COMMITS_ID'),
notifReleases: read('CHANNEL_NOTIF_RELEASES_ID'),
notifErrors: read('CHANNEL_NOTIF_ERRORS_ID'),
ticketCategory: read('CATEGORY_TICKETS_ID'),
voiceTrigger: read('CHANNEL_VOICE_TRIGGER_ID'),
voiceCategory: read('CATEGORY_VOICE_ID'),
},
voice: {
emptyGraceMs: readDuration('VOICE_EMPTY_GRACE_MS', 5_000),
},
bot: {
statusIntervalSeconds: readDuration('BOT_STATUS_INTERVAL_SECONDS', 60),
},
gitea: {
url: read('GITEA_URL').replace(/\/+$/, ''),
token: read('GITEA_TOKEN'),
owner: read('GITEA_OWNER'),
repo: read('GITEA_REPO'),
timeoutMs: readInt('GITEA_TIMEOUT_MS', 10_000),
maxRetries: readInt('GITEA_MAX_RETRIES', 2),
},
webhook: {
enabled: readBool('WEBHOOK_ENABLED'),
host: read('WEBHOOK_HOST', '0.0.0.0'),
port: readInt('WEBHOOK_PORT', 3000),
path: read('WEBHOOK_PATH', '/webhooks/gitea'),
secret: read('GITEA_WEBHOOK_SECRET'),
},
database: {
path: read('DATABASE_PATH', './data/fws-bot.sqlite'),
backupDir: read('BACKUP_DIR', './data/backups'),
},
links: {
website: read('FWS_WEBSITE_URL'),
docs: read('FWS_DOCS_URL'),
discordInvite: read('FWS_DISCORD_INVITE_URL'),
archRepo: read('FWS_ARCH_REPO_URL'),
},
});
/** Values that must never appear in Discord messages or logs. */
export const secrets = [env.discord.token, env.gitea.token, env.webhook.secret].filter(Boolean);
export function assertRequiredEnv(keys) {
const missing = keys.filter((key) => !read(key));
if (missing.length > 0) {
throw new Error(`Missing required environment variables: ${missing.join(', ')}`);
}
}