mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-23 00:21:28 +00:00
feat: add Discord role mention support to routes
This commit is contained in:
parent
869d84d78c
commit
76ba2c0a89
17 changed files with 201 additions and 14 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { describe, it, expect, beforeEach, afterEach } from "bun:test";
|
||||
import { sendMessage } from "../drivers/discord/rest";
|
||||
import { renderNeutralMessage } from "../drivers/discord/render";
|
||||
import { dispatchEvent } from "../core/dispatch";
|
||||
import type { Env, Route } from "../types";
|
||||
|
||||
|
|
@ -68,6 +69,22 @@ describe("discord-rest sendMessage", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("discord role mentions", () => {
|
||||
it("renders mentionRoleIds into the message content", () => {
|
||||
const out = renderNeutralMessage({
|
||||
title: "T",
|
||||
mentionRoleIds: ["111", "222"],
|
||||
});
|
||||
expect(out.content).toBe("<@&111> <@&222>");
|
||||
expect(out.embeds?.[0]?.title).toBe("T");
|
||||
});
|
||||
|
||||
it("omits content when no roles are mentioned", () => {
|
||||
const out = renderNeutralMessage({ title: "T" });
|
||||
expect(out.content).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("dispatchEvent fallback routing", () => {
|
||||
function createMockKV(): KVNamespace {
|
||||
const store = new Map<string, string>();
|
||||
|
|
@ -169,4 +186,33 @@ describe("dispatchEvent fallback routing", () => {
|
|||
expect(sent.filter((u) => u.includes("/111/"))).toHaveLength(0);
|
||||
expect(sent.filter((u) => u.includes("/222/"))).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("prepends role mentions to the Discord message content", async () => {
|
||||
const bodies: string[] = [];
|
||||
mockFetch((url, init) => {
|
||||
bodies.push(String(init?.body ?? ""));
|
||||
return new Response("{}", { status: 200 });
|
||||
});
|
||||
const env = createEnv({ KV: createMockKV(), DB: createMockDB() });
|
||||
const routes: Route[] = [
|
||||
{
|
||||
id: "mention-push",
|
||||
name: "Mention Push",
|
||||
enabled: true,
|
||||
discordRoleIds: ["111", "222"],
|
||||
filters: [{ type: "event", match: "push" }],
|
||||
targets: [{ channelId: "333" }],
|
||||
},
|
||||
];
|
||||
|
||||
await dispatchEvent({ ...baseConfig, routes }, { event: "push", payload: {} }, env);
|
||||
|
||||
expect(bodies).toHaveLength(1);
|
||||
const parsed = JSON.parse(bodies[0]!) as {
|
||||
content?: string;
|
||||
embeds?: Array<{ title?: string }>;
|
||||
};
|
||||
expect(parsed.content).toBe("<@&111> <@&222>");
|
||||
expect(parsed.embeds?.[0]).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue