fix(discord): guard @everyone shortcut against bot-authored messages

Preserve the !author.bot || sender.isPluralKit guard when short-circuiting
wasMentioned on mentionedEveryone, so bot relay messages don't spuriously
trigger mention-gate logic. Add test coverage for the wasMentioned path.
This commit is contained in:
geekhuashan
2026-04-03 23:16:23 +08:00
committed by Peter Steinberger
parent 0b69119f1b
commit 6ba490ec7b
2 changed files with 42 additions and 1 deletions

View File

@@ -721,6 +721,47 @@ describe("preflightDiscordMessage", () => {
expect(result?.hasAnyMention).toBe(false);
});
it("does not treat bot-sent @everyone as wasMentioned", async () => {
const channelId = "channel-everyone-2";
const guildId = "guild-everyone-2";
const client = createGuildTextClient(channelId);
const message = createDiscordMessage({
id: "m-everyone-2",
channelId,
content: "@everyone relay message",
mentionedEveryone: true,
author: {
id: "relay-bot-2",
bot: true,
username: "RelayBot",
},
});
const result = await preflightDiscordMessage({
...createPreflightArgs({
cfg: DEFAULT_PREFLIGHT_CFG,
discordConfig: {
allowBots: true,
} as DiscordConfig,
data: createGuildEvent({
channelId,
guildId,
author: message.author,
message,
}),
client,
}),
guildEntries: {
[guildId]: {
requireMention: false,
},
},
});
expect(result).not.toBeNull();
expect(result?.wasMentioned).toBe(false);
});
it("uses attachment content_type for guild audio preflight mention detection", async () => {
transcribeFirstAudioMock.mockResolvedValue("hey openclaw");

View File

@@ -753,7 +753,7 @@ export async function preflightDiscordMessage(
const mentionText = hasTypedText ? baseText : "";
const wasMentioned =
!isDirectMessage &&
(Boolean(message.mentionedEveryone) ||
(((!author.bot || sender.isPluralKit) && Boolean(message.mentionedEveryone)) ||
matchesMentionWithExplicit({
text: mentionText,
mentionRegexes,