Show the destination, result and loot in Sokko TCG Discord alerts, with a button to the expedition
- Each queued alert keeps an embed and a link button: the destination illustration as thumbnail, the tier, score and loot for a return, the difficulty and automatic departure for a new group. - The button and the message link open #/cards/expeditions/<id>, which scrolls to the player's expedition or group and highlights it; Discord login now returns to that link. - Without an https CARDS_PUBLIC_ORIGIN the link stays in the text, without button or thumbnail, which Discord would refuse. - Delivery docs name palico-bot's NOTIFICATIONS_API_KEY and its local-only route on port 3101. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
734a3b6a8b
commit
82cebd0fd1
17 changed files with 184 additions and 37 deletions
|
|
@ -58,7 +58,7 @@ test("Discord OAuth preserves the dedicated admin route", async (t) => {
|
|||
const oauthCookies = authorization.headers["set-cookie"];
|
||||
assert.ok(oauthCookies.some((cookie) => cookie.startsWith("sokkog_cards_oauth_return=%2Fcards%2Fadmin;")));
|
||||
// Le retour après connexion accepte les sections joueur, jamais une adresse hors de Sokko TCG.
|
||||
for (const [returnTo, expected] of [["/cards/shop", "%2Fcards%2Fshop"], ["/cards/admin/collections/nebula", "%2Fcards%2Fadmin%2Fcollections%2Fnebula"], ["/cards/shop/extra", "%2Fcards"], ["//evil.example/cards", "%2Fcards"], ["/cards/../toolboxes", "%2Fcards"]]) {
|
||||
for (const [returnTo, expected] of [["/cards/shop", "%2Fcards%2Fshop"], ["/cards/admin/collections/nebula", "%2Fcards%2Fadmin%2Fcollections%2Fnebula"], ["/cards/shop/extra", "%2Fcards"], ["/cards/expeditions/34d49df0-2a37-4ba1-83a5-1832ed81c885", "%2Fcards%2Fexpeditions%2F34d49df0-2a37-4ba1-83a5-1832ed81c885"], ["//evil.example/cards", "%2Fcards"], ["/cards/../toolboxes", "%2Fcards"]]) {
|
||||
const response = await call(handler, { path: `/api/cards/auth/discord?returnTo=${encodeURIComponent(returnTo)}` });
|
||||
assert.ok(response.headers["set-cookie"].some((cookie) => cookie.startsWith(`sokkog_cards_oauth_return=${expected};`)), returnTo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1117,7 +1117,11 @@ test("Discord alerts stay off until a player opts in, then queue group openings
|
|||
let pending = service.expeditions.pendingAlerts();
|
||||
assert.equal(pending.length, 1);
|
||||
assert.equal(pending[0].discordId, "123456789012345678");
|
||||
assert.match(pending[0].content, /Player ouvre un groupe d’expédition vers .+ Rejoignez-le sur le tableau de la Guilde : https:\/\/sokko\.example\/#\/cards\/expeditions$/);
|
||||
assert.match(pending[0].content, /Player ouvre un groupe d’expédition vers .+ Rejoignez-le sur le tableau de la Guilde : https:\/\/sokko\.example\/#\/cards\/expeditions\/[0-9a-f-]{36}$/);
|
||||
// L'embed montre la destination en vignette ; le bouton ouvre directement le groupe.
|
||||
assert.match(pending[0].extra.embed.title, /^Nouveau groupe vers /);
|
||||
assert.match(pending[0].extra.embed.thumbnail, /^https:\/\/sokko\.example\/static\/img\//);
|
||||
assert.deepEqual(pending[0].extra.link, { label: "Rejoindre le groupe", url: `https://sokko.example/#/cards/expeditions/${group.id}` });
|
||||
assert.equal(silent.id === friend.id, false);
|
||||
|
||||
// Retours : une alerte par membre qui l'a activée, une seule fois.
|
||||
|
|
@ -1127,6 +1131,10 @@ test("Discord alerts stay off until a player opts in, then queue group openings
|
|||
clock.now += 2 * HOUR;
|
||||
assert.equal(service.expeditions.queueReturnAlerts(), 2);
|
||||
assert.equal(service.expeditions.queueReturnAlerts(), 0);
|
||||
const returned = JSON.parse(database.db.prepare("SELECT extra_json FROM alert_outbox WHERE kind = 'expedition_returned' LIMIT 1").get().extra_json);
|
||||
assert.equal(returned.embed.title, "Votre expédition est de retour !");
|
||||
assert.deepEqual(returned.embed.fields.map((field) => field.name), ["Résultat", "Butin"]);
|
||||
assert.equal(returned.link.label, "Voir l’expédition");
|
||||
|
||||
// Envoi : un succès, un échec définitif, un échec qu'on réessaie.
|
||||
const outcomes = [null, Object.assign(new Error("palico-bot answered 422"), { permanent: true }), new Error("timeout")];
|
||||
|
|
@ -1205,9 +1213,9 @@ test("the alert sender posts to palico-bot with its key and flags permanent refu
|
|||
return { ok: answers[0] < 300, status: answers.shift() };
|
||||
}
|
||||
});
|
||||
await send("123456789012345678", "Bonjour");
|
||||
await send("123456789012345678", "Bonjour", { embed: { title: "Retour" }, link: { label: "Voir", url: "https://sokko.example/#/cards/expeditions/abc" } });
|
||||
assert.equal(calls[0].options.headers.Authorization, "Bearer secret");
|
||||
assert.deepEqual(JSON.parse(calls[0].options.body), { userId: "123456789012345678", content: "Bonjour" });
|
||||
assert.deepEqual(JSON.parse(calls[0].options.body), { userId: "123456789012345678", content: "Bonjour", embed: { title: "Retour" }, link: { label: "Voir", url: "https://sokko.example/#/cards/expeditions/abc" } });
|
||||
await assert.rejects(send("123456789012345678", "x"), (error) => error.permanent === true);
|
||||
await assert.rejects(send("123456789012345678", "x"), (error) => error.permanent === false);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -653,3 +653,33 @@ test("progression plans: the default keeps today's stats, vocations reach the ca
|
|||
assert.match(allocationError({ bravoure: 10, fortune: 11 }, 20, settings), /20 points/);
|
||||
assert.ok(allocationError({ magic: 1 }, 20, settings));
|
||||
});
|
||||
|
||||
test("Discord alert messages carry an embed and a direct link, with the interface's labels", async () => {
|
||||
const { expeditionReturnedMessage, groupOpenedMessage, ITEM_LABELS, lootLine, TIER_LABELS } = await import("../services/cards/alert-messages.js");
|
||||
const { ITEM_IDS } = await import("../services/cards/expedition-rules.js");
|
||||
const site = JSON.parse(await readFile("website/public/data/site.json", "utf8")).cards.expeditions;
|
||||
assert.deepEqual(Object.keys(ITEM_LABELS).sort(), [...ITEM_IDS].sort());
|
||||
for (const id of ITEM_IDS) assert.equal(ITEM_LABELS[id], site.items[id], id);
|
||||
assert.deepEqual(TIER_LABELS, site.tiers);
|
||||
|
||||
const destination = destinations[0];
|
||||
const setup = { destination, stars: 3, hours: 6, recruitUntil: Date.parse("2026-11-29T20:00:00Z") };
|
||||
const group = groupOpenedMessage({ creatorName: "Mira", setup, expeditionId: "abc", origin: "https://sokko.example", catalog });
|
||||
assert.match(group.content, /^Mira ouvre un groupe d’expédition vers .+ \(★★★ · 6 h\)\. Rejoignez-le sur le tableau de la Guilde : https:\/\/sokko\.example\/#\/cards\/expeditions\/abc$/);
|
||||
assert.equal(group.embed.url, "https://sokko.example/#/cards/expeditions/abc");
|
||||
assert.ok(group.embed.thumbnail.startsWith("https://sokko.example/static/"));
|
||||
assert.deepEqual(group.embed.fields.at(-1), { name: "Départ automatique", value: `<t:${Date.parse("2026-11-29T20:00:00Z") / 1000}:R>`, inline: true });
|
||||
|
||||
const reward = { eclats: 16, stardust: 2, packs: [], items: ["guideStar", "guideStar", "anchor"], cards: ["starvoid-dragon-standard"] };
|
||||
assert.equal(lootLine(reward, catalog), "+16 Éclats · +2 poussières · Dragon du Néant Étoilé · Étoile guide ×2 · Ancre des Veilleurs");
|
||||
assert.equal(lootLine({ eclats: 0, stardust: 0 }, catalog), "Rien cette fois");
|
||||
const back = expeditionReturnedMessage({ setup, result: { tier: "triumph", scorePct: 128.5 }, reward, expeditionId: "abc", origin: "https://sokko.example", catalog });
|
||||
assert.equal(back.embed.color, 0xf6c453);
|
||||
assert.deepEqual(back.embed.fields[0], { name: "Résultat", value: "Triomphe · 128,5 %", inline: true });
|
||||
assert.deepEqual(back.link, { label: "Voir l’expédition", url: "https://sokko.example/#/cards/expeditions/abc" });
|
||||
// En développement (http) : le lien reste dans le texte, mais ni bouton ni vignette, que Discord refuserait.
|
||||
const local = expeditionReturnedMessage({ setup, result: null, reward: null, expeditionId: "abc", origin: "http://localhost:5173", catalog });
|
||||
assert.match(local.content, /http:\/\/localhost:5173\/#\/cards\/expeditions\/abc$/);
|
||||
assert.deepEqual([local.link, local.embed.thumbnail, local.embed.url], [null, undefined, undefined]);
|
||||
assert.equal(groupOpenedMessage({ creatorName: "", setup, expeditionId: "abc", origin: null, catalog }).link, undefined);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue