feat(discord): auto-resolve user mentions in message content#20697
feat(discord): auto-resolve user mentions in message content#20697tdjackey wants to merge 2 commits intoopenclaw:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0cb7e10eb9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (Array.isArray(mentions)) { | ||
| for (const user of mentions) { | ||
| const label = user.global_name || user.username; | ||
| out = out.replace(new RegExp(`<@!?${user.id}>`, "g"), `@${label}`); |
There was a problem hiding this comment.
Escape replacement text when inserting mention labels
resolveDiscordMentions passes @${label} directly as the replacement string, but JavaScript treats $ sequences in replacement strings as special tokens ($&, $1, etc.). If a Discord global_name/username contains $ (which is valid for display names), the resolved text is corrupted (for example, $& re-inserts the original <@...> token), so mention normalization can fail for real users. Use a replacer function (e.g. replace(regex, () => ...)) or escape $ in the label before replacing.
Useful? React with 👍 / 👎.
|
This pull request has been automatically marked as stale due to inactivity. |
|
Superseded by #33224. |
Summary
Resolves Discord user mentions (e.g.,
<@123>) in incoming message content to human-readable names (e.g.,@Alice) using the message'smentionsmetadata.Fixes #20617.
Implementation
resolveDiscordMentionshelper inmessage-utils.tsglobal_name(priority) orusername<@id>and<@!id>formatsImpact
@Alice helloinstead of<@12345> helloGreptile Summary
Adds user mention resolution to Discord message content, converting
<@id>format to readable names like@Alice. The implementation correctly prioritizesglobal_nameoverusernameand handles both<@id>and<@!id>formats. The change is scoped to the message text resolution flow and includes appropriate test coverage for basic cases.Confidence Score: 5/5
Last reviewed commit: 0cb7e10
(4/5) You can add custom instructions or style guidelines for the agent here!