mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-30 21:03:35 +00:00
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:
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user