@@ -3,9 +3,10 @@ import { Routes, type APIMessage } from "discord-api-types/v10";
33import { formatAllowlistMatchMeta } from "openclaw/plugin-sdk/allow-from" ;
44import {
55 buildMentionRegexes ,
6+ implicitMentionKindWhen ,
67 logInboundDrop ,
78 matchesMentionWithExplicit ,
8- resolveMentionGatingWithBypass ,
9+ resolveInboundMentionDecision ,
910} from "openclaw/plugin-sdk/channel-inbound" ;
1011import { resolveControlCommandGate } from "openclaw/plugin-sdk/command-auth-native" ;
1112import { hasControlCommand } from "openclaw/plugin-sdk/command-detection" ;
@@ -181,10 +182,10 @@ function resolveDiscordMentionState(params: {
181182 referencedAuthorId ?: string ;
182183 senderIsPluralKit : boolean ;
183184 transcript ?: string ;
184- } ) : { implicitMention : boolean ; wasMentioned : boolean } {
185+ } ) {
185186 if ( params . isDirectMessage ) {
186187 return {
187- implicitMention : false ,
188+ implicitMentionKinds : [ ] ,
188189 wasMentioned : false ,
189190 } ;
190191 }
@@ -203,12 +204,15 @@ function resolveDiscordMentionState(params: {
203204 } ,
204205 transcript : params . transcript ,
205206 } ) ;
206- const implicitMention = Boolean (
207- params . botId && params . referencedAuthorId && params . referencedAuthorId === params . botId ,
207+ const implicitMentionKinds = implicitMentionKindWhen (
208+ "reply_to_bot" ,
209+ Boolean ( params . botId ) &&
210+ Boolean ( params . referencedAuthorId ) &&
211+ params . referencedAuthorId === params . botId ,
208212 ) ;
209213
210214 return {
211- implicitMention ,
215+ implicitMentionKinds ,
212216 wasMentioned,
213217 } ;
214218}
@@ -887,7 +891,7 @@ export async function preflightDiscordMessage(
887891 }
888892
889893 const mentionText = hasTypedText ? baseText : "" ;
890- const { implicitMention , wasMentioned } = resolveDiscordMentionState ( {
894+ const { implicitMentionKinds , wasMentioned } = resolveDiscordMentionState ( {
891895 authorIsBot : Boolean ( author . bot ) ,
892896 botId,
893897 hasAnyMention,
@@ -946,23 +950,27 @@ export async function preflightDiscordMessage(
946950 }
947951
948952 const canDetectMention = Boolean ( botId ) || mentionRegexes . length > 0 ;
949- const mentionGate = resolveMentionGatingWithBypass ( {
950- isGroup : isGuildMessage ,
951- requireMention : Boolean ( shouldRequireMention ) ,
952- canDetectMention,
953- wasMentioned,
954- implicitMention,
955- hasAnyMention,
956- allowTextCommands,
957- hasControlCommand : hasControlCommandInMessage ,
958- commandAuthorized,
953+ const mentionDecision = resolveInboundMentionDecision ( {
954+ facts : {
955+ canDetectMention,
956+ wasMentioned,
957+ hasAnyMention,
958+ implicitMentionKinds,
959+ } ,
960+ policy : {
961+ isGroup : isGuildMessage ,
962+ requireMention : Boolean ( shouldRequireMention ) ,
963+ allowTextCommands,
964+ hasControlCommand : hasControlCommandInMessage ,
965+ commandAuthorized,
966+ } ,
959967 } ) ;
960- const effectiveWasMentioned = mentionGate . effectiveWasMentioned ;
968+ const effectiveWasMentioned = mentionDecision . effectiveWasMentioned ;
961969 logDebug (
962- `[discord-preflight] shouldRequireMention=${ shouldRequireMention } baseRequireMention=${ shouldRequireMentionByConfig } boundThreadSession=${ isBoundThreadSession } mentionGate .shouldSkip=${ mentionGate . shouldSkip } wasMentioned=${ wasMentioned } ` ,
970+ `[discord-preflight] shouldRequireMention=${ shouldRequireMention } baseRequireMention=${ shouldRequireMentionByConfig } boundThreadSession=${ isBoundThreadSession } mentionDecision .shouldSkip=${ mentionDecision . shouldSkip } wasMentioned=${ wasMentioned } ` ,
963971 ) ;
964972 if ( isGuildMessage && shouldRequireMention ) {
965- if ( botId && mentionGate . shouldSkip ) {
973+ if ( botId && mentionDecision . shouldSkip ) {
966974 logDebug ( `[discord-preflight] drop: no-mention` ) ;
967975 logVerbose ( `discord: drop guild message (mention required, botId=${ botId } )` ) ;
968976 logger . info (
@@ -983,7 +991,7 @@ export async function preflightDiscordMessage(
983991 }
984992
985993 if ( author . bot && ! sender . isPluralKit && allowBotsMode === "mentions" ) {
986- const botMentioned = isDirectMessage || wasMentioned || implicitMention ;
994+ const botMentioned = isDirectMessage || wasMentioned || mentionDecision . implicitMention ;
987995 if ( ! botMentioned ) {
988996 logDebug ( `[discord-preflight] drop: bot message missing mention (allowBots=mentions)` ) ;
989997 logVerbose ( "discord: drop bot message (allowBots=mentions, missing mention)" ) ;
@@ -998,7 +1006,7 @@ export async function preflightDiscordMessage(
9981006 ignoreOtherMentions &&
9991007 hasUserOrRoleMention &&
10001008 ! wasMentioned &&
1001- ! implicitMention
1009+ ! mentionDecision . implicitMention
10021010 ) {
10031011 logDebug ( `[discord-preflight] drop: other-mention` ) ;
10041012 logVerbose (
@@ -1103,7 +1111,7 @@ export async function preflightDiscordMessage(
11031111 shouldRequireMention,
11041112 hasAnyMention,
11051113 allowTextCommands,
1106- shouldBypassMention : mentionGate . shouldBypassMention ,
1114+ shouldBypassMention : mentionDecision . shouldBypassMention ,
11071115 effectiveWasMentioned,
11081116 canDetectMention,
11091117 historyEntry,
0 commit comments