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

84
test/invitation.test.js Normal file
View file

@ -0,0 +1,84 @@
import test from "node:test";
import assert from "node:assert/strict";
import { DiscordjsErrorCodes } from "discord.js";
import {
InvitationError,
buildInvitationMessage,
checkInvitation,
parseInviteCode,
} from "../src/features/invitation.js";
const GUILD_ID = "111111111111111111";
function fakeGuild({ invite = null, fetchError = null } = {}) {
return {
id: GUILD_ID,
invites: {
async fetch() {
if (fetchError) throw fetchError;
if (!invite) throw Object.assign(new Error("not found"), { code: DiscordjsErrorCodes.InviteNotFound });
return invite;
},
},
};
}
function fakeClient(publicInvite) {
return {
async fetchInvite() {
if (!publicInvite) throw Object.assign(new Error("Unknown Invite"), { code: 10006 });
return publicInvite;
},
};
}
test("parseInviteCode accepts invite links and bare codes only", () => {
for (const input of ["https://discord.gg/AbC-12", "discord.gg/AbC-12", "https://discord.com/invite/AbC-12", " AbC-12 "]) {
assert.equal(parseInviteCode(input), "AbC-12", input);
}
for (const input of ["https://evil.example/AbC-12", "https://discord.gg/", "a b", "", undefined]) {
assert.equal(parseInviteCode(input), null, String(input));
}
});
test("a temporary invite without limits is published as is", async () => {
const guild = fakeGuild({ invite: { code: "AbC-12", temporary: true, maxUses: 0, expiresTimestamp: null } });
assert.deepEqual(await checkInvitation(guild, fakeClient(), "discord.gg/AbC-12"), {
link: "https://discord.gg/AbC-12",
warnings: [],
});
});
test("permanent and unknown invites are refused", async () => {
const permanent = fakeGuild({ invite: { code: "AbC-12", temporary: false } });
await assert.rejects(checkInvitation(permanent, fakeClient(), "AbC-12"), InvitationError);
await assert.rejects(checkInvitation(fakeGuild(), fakeClient(), "AbC-12"), InvitationError);
await assert.rejects(checkInvitation(fakeGuild(), fakeClient(), "pas un lien"), InvitationError);
});
test("limited or expiring invites are published with warnings", async () => {
const guild = fakeGuild({
invite: { code: "AbC-12", temporary: true, maxUses: 5, uses: 2, expiresTimestamp: 1_800_000_000_000 },
});
const { warnings } = await checkInvitation(guild, fakeClient(), "AbC-12");
assert.equal(warnings.length, 2);
});
test("without Manage Server the bot checks only the guild", async () => {
const missingPermissions = Object.assign(new Error("Missing Permissions"), { code: 50013 });
const guild = fakeGuild({ fetchError: missingPermissions });
const sameGuild = fakeClient({ code: "AbC-12", guild: { id: GUILD_ID }, temporary: null });
const result = await checkInvitation(guild, sameGuild, "AbC-12");
assert.equal(result.link, "https://discord.gg/AbC-12");
assert.equal(result.warnings.length, 1);
const otherGuild = fakeClient({ code: "AbC-12", guild: { id: "222222222222222222" }, temporary: null });
await assert.rejects(checkInvitation(guild, otherGuild, "AbC-12"), InvitationError);
});
test("the invitation message shows the link and how to stay permanently", () => {
const message = buildInvitationMessage("https://discord.gg/AbC-12");
assert.match(message, /```\nhttps:\/\/discord\.gg\/AbC-12\n```/);
assert.match(message, /Hangaround/);
});