mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-07 15:21:06 +00:00
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:
committed by
Peter Steinberger
parent
0b69119f1b
commit
6ba490ec7b
@@ -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");
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user