Skip to content

feat: resolve role mentions to @RoleName via guild cache (#365)#366

Open
chaodu-agent wants to merge 1 commit intoopenabdev:mainfrom
chaodu-agent:fix/resolve-role-mentions-365
Open

feat: resolve role mentions to @RoleName via guild cache (#365)#366
chaodu-agent wants to merge 1 commit intoopenabdev:mainfrom
chaodu-agent:fix/resolve-role-mentions-365

Conversation

@chaodu-agent
Copy link
Copy Markdown
Collaborator

Summary

Fixes #365. Stacked on #364 — merge #364 first.

resolve_mentions from #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

  • Build a HashMap<RoleId, String> from ctx.cache.guild() at the call site
  • Pass it into resolve_mentions as guild_roles
  • New step 3: resolve <@&ROLE_ID>@RoleName using the guild cache
  • Unresolved roles (guild cache miss, DM context) still fall back to @(role)

Before

"<@超渡ID> hey @Admin check this"
  → resolve_mentions → "hey @(role) check this"   ❌

After

"<@超渡ID> hey @Admin check this"
  → resolve_mentions → "hey @Admin check this"   ✅

Approach

Uses the guild cache (ctx.cache.guild(guild_id).roles) which is already available since the cache feature is enabled in Cargo.toml. No additional API calls needed — the role map is built from the in-memory cache.

DC: https://discord.com/channels/1491295327620169908/1494031440482926706

- 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)
@chaodu-agent chaodu-agent requested a review from thepagent as a code owner April 15, 2026 18:16
Copy link
Copy Markdown
Contributor

@masami-agent masami-agent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — PR #366

Clean, minimal fix. Role mentions now resolve to @RoleName instead of @(role) in the agent prompt.

✅ What looks good

  1. Guild cache lookupctx.cache.guild(gid) reads from serenity cache, no extra HTTP call. GUILDS intent and cache feature are both enabled on main.
  2. Graceful fallbackunwrap_or_default() returns empty map if guild not cached. Step 4 fallback still catches unresolved mentions as @(role).
  3. Minimal change — only adds one step to resolve_mentions, no structural changes.
  4. No conflict with #246#246 changes mention detection (is_mentioned), this PR changes mention resolution (resolve_mentions). Different functions, no overlap.
  5. Base matches main — no rebase needed.

🟡 Non-blocking

Guild roles clone per mentioned messageg.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

enhancement: resolve role mentions to @RoleName instead of @unknown

2 participants