Fix deploy and lock down the DM route; add /invitation
All checks were successful
Deploy Palico Bot / deploy (push) Successful in 32s

- Deploy workflow: pin node:24-bookworm; install openssh-client only if missing
- Auth failure limiter counts only 401s (422/404 no longer lock out clients)
- trust proxy configurable (WEB_TRUSTED_PROXIES), never "true"
- DM route: loopback connections only, dedicated NOTIFICATIONS_API_KEY, 503 when unset
- Jukebox: no polling without a key, stop on 401
- /invitation: posts the temporary invite message after checking the link
- Stop tracking storage/library.json; README describes the real deployment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-29 10:57:22 +01:00
parent 3655b1ad74
commit 6895d20459
16 changed files with 554 additions and 99 deletions

View file

@ -0,0 +1,90 @@
// Message d'invitation : le serveur n'autorise pas ses membres à créer des invitations ; un seul
// lien à adhésion temporaire est partagé par le bot. Pour garder quelqu'un, on lui donne un rôle.
import { codeBlock, DiscordjsErrorCodes } from "discord.js";
const INVITE_URL_PATTERN =
/^(?:https?:\/\/)?(?:www\.)?discord(?:(?:app)?\.com\/invite|\.gg(?:\/invite)?)\/([\w-]{2,255})\/?$/i;
const INVITE_CODE_PATTERN = /^[\w-]{2,255}$/;
// Codes de l'API Discord : invitation inconnue, permission manquante.
const UNKNOWN_INVITE = 10006;
const MISSING_PERMISSIONS = 50013;
class InvitationError extends Error {}
function parseInviteCode(input) {
const value = String(input ?? "").trim();
const match = INVITE_URL_PATTERN.exec(value);
if (match) return match[1];
return INVITE_CODE_PATTERN.test(value) ? value : null;
}
async function fetchPublicInvite(client, code, guild) {
let invite;
try {
invite = await client.fetchInvite(code);
} catch (error) {
if (error?.code === UNKNOWN_INVITE) {
throw new InvitationError("Cette invitation n'existe pas ou a expiré.");
}
throw error;
}
if (invite.guild?.id !== guild.id) {
throw new InvitationError("Cette invitation mène à un autre serveur.");
}
return invite;
}
// Vérifie le lien avant de le publier. Renvoie le lien normalisé et des avertissements ;
// lève InvitationError si le lien ne doit pas être publié.
async function checkInvitation(guild, client, input) {
const code = parseInviteCode(input);
if (!code) {
throw new InvitationError("Lien d'invitation invalide.");
}
const warnings = [];
let invite;
try {
// Seule la liste des invitations du serveur dit si l'invitation est temporaire
// (permission « Gérer le serveur »).
invite = await guild.invites.fetch({ code, force: true, cache: false });
} catch (error) {
if (error?.code === DiscordjsErrorCodes.InviteNotFound) {
throw new InvitationError("Cette invitation n'existe pas sur ce serveur.");
}
if (error?.code !== MISSING_PERMISSIONS) {
throw error;
}
invite = await fetchPublicInvite(client, code, guild);
warnings.push(
"Le bot n'a pas la permission « Gérer le serveur » : impossible de vérifier que l'invitation est temporaire."
);
}
if (invite.temporary === false) {
throw new InvitationError(
"Cette invitation donne un accès permanent : crée-la avec l'option « Accorder une adhésion temporaire »."
);
}
if (invite.maxUses) {
warnings.push(`Utilisations limitées : ${invite.uses ?? 0}/${invite.maxUses}.`);
}
if (invite.expiresTimestamp) {
warnings.push(`Elle expire le <t:${Math.floor(invite.expiresTimestamp / 1000)}:f>.`);
}
return { link: `https://discord.gg/${invite.code}`, warnings };
}
function buildInvitationMessage(link) {
return (
"Pour inviter quelqu'un, il faut utiliser cette invitation temporaire !\n" +
codeBlock(link) +
"*Pour une invitation permanente, il suffit d'attribuer le role*" +
" ***Hangaround*** " +
"*à la personne concernée.*\n\n" +
"​"
);
}
export { InvitationError, buildInvitationMessage, checkInvitation, parseInviteCode };