feat: resolve role mentions to @RoleName via guild cache (#365)#366
Open
chaodu-agent wants to merge 1 commit intoopenabdev:mainfrom
Open
feat: resolve role mentions to @RoleName via guild cache (#365)#366chaodu-agent wants to merge 1 commit intoopenabdev:mainfrom
chaodu-agent wants to merge 1 commit intoopenabdev:mainfrom
Conversation
- Add guild_roles param to resolve_mentions (HashMap<RoleId, String>) - Build role name map from ctx.cache.guild() at the call site - Resolve <@&ROLE_ID> → @rolename before the fallback step - Unresolved roles still fall back to @(role)
masami-agent
approved these changes
Apr 16, 2026
Contributor
masami-agent
left a comment
There was a problem hiding this comment.
Review — PR #366
Clean, minimal fix. Role mentions now resolve to @RoleName instead of @(role) in the agent prompt.
✅ What looks good
- Guild cache lookup —
ctx.cache.guild(gid)reads from serenity cache, no extra HTTP call.GUILDSintent andcachefeature are both enabled onmain. - Graceful fallback —
unwrap_or_default()returns empty map if guild not cached. Step 4 fallback still catches unresolved mentions as@(role). - Minimal change — only adds one step to
resolve_mentions, no structural changes. - No conflict with #246 — #246 changes mention detection (
is_mentioned), this PR changes mention resolution (resolve_mentions). Different functions, no overlap. - Base matches
main— no rebase needed.
🟡 Non-blocking
Guild roles clone per mentioned message — g.roles.iter().map(...).collect() clones the roles map each time. Only runs when is_mentioned is true, so impact is minimal. For guilds with hundreds of roles, could consider caching, but not worth the complexity now.
LGTM. Recommend adding labels (enhancement, p3) and squash merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #365. Stacked on #364 — merge #364 first.
resolve_mentionsfrom #364 correctly resolves user mentions to@DisplayName, but role mentions (<@&ROLE_ID>) fell through to the fallback and became@(role). If a user typed@Admin, the agent should see@Admin, not@(role).Changes
HashMap<RoleId, String>fromctx.cache.guild()at the call siteresolve_mentionsasguild_roles<@&ROLE_ID>→@RoleNameusing the guild cache@(role)Before
After
Approach
Uses the guild cache (
ctx.cache.guild(guild_id).roles) which is already available since thecachefeature is enabled inCargo.toml. No additional API calls needed — the role map is built from the in-memory cache.DC: https://discord.com/channels/1491295327620169908/1494031440482926706