fix(discord): expose sender bot status in context (#97824)

* fix(discord): expose sender bot status in context

* fix(discord): expose sender bot status in context

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
Masato Hoshino
2026-07-01 02:27:53 +09:00
committed by GitHub
parent c896718acb
commit 984f5a51ca
2 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
// Discord tests cover sender bot-status forwarding into the inbound context payload.
import { describe, expect, it } from "vitest";
import { buildDiscordMessageProcessContext } from "./message-handler.context.js";
import { createBaseDiscordMessageContext } from "./message-handler.test-harness.js";
describe("discord buildDiscordMessageProcessContext sender bot status", () => {
it("forwards bot author status to ctxPayload.SenderIsBot", async () => {
const ctx = await createBaseDiscordMessageContext({
author: { id: "U1", username: "alice", discriminator: "0", globalName: "Alice", bot: true },
});
const result = await buildDiscordMessageProcessContext({ ctx, text: "hi", mediaList: [] });
if (!result) {
throw new Error("expected a built Discord message context");
}
expect(result.ctxPayload.SenderIsBot).toBe(true);
});
it("omits SenderIsBot for human authors", async () => {
const ctx = await createBaseDiscordMessageContext();
const result = await buildDiscordMessageProcessContext({ ctx, text: "hi", mediaList: [] });
if (!result) {
throw new Error("expected a built Discord message context");
}
expect(result.ctxPayload.SenderIsBot).toBeUndefined();
});
it("omits SenderIsBot for PluralKit proxy senders despite the bot author", async () => {
const ctx = await createBaseDiscordMessageContext({
author: { id: "U1", username: "pk", discriminator: "0", globalName: "PK", bot: true },
sender: { label: "user", name: "Member", tag: "member", isPluralKit: true },
});
const result = await buildDiscordMessageProcessContext({ ctx, text: "hi", mediaList: [] });
if (!result) {
throw new Error("expected a built Discord message context");
}
expect(result.ctxPayload.SenderIsBot).toBeUndefined();
});
});

View File

@@ -335,6 +335,10 @@ export async function buildDiscordMessageProcessContext(params: {
tag: sender.tag,
roles: memberRoleIds,
displayLabel: senderLabel,
// PluralKit proxies post under a bot author but represent a human member,
// whose identity already replaced the sender fields here; only mark
// genuine (non-PluralKit) bot authors as bots.
isBot: author.bot && !sender.isPluralKit ? true : undefined,
},
conversation: {
kind: isDirectMessage ? "direct" : "channel",