refactor(addmod): allow adding all users with a specific role - #404
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the add staff / remove staff commands (slash + text) to accept either a user or a role, enabling bulk add/remove of all members of a role to/from a ticket thread with validation, limits, and updated i18n.
Changes:
- Introduces shared target parsing (
AddTarget,parse_add_target) and role-member helpers (members_with_role, bulk add/remove outcomes). - Updates add/remove staff text and slash commands to accept a “mentionable” target (user or role) and to report success/partial/limits.
- Expands English/French translations for new outcomes and improves error messages with
{error}details.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustmail/src/i18n/language/fr.rs | Adds FR strings for role add/remove outcomes; updates help + argument descriptions; updates Discord API error message to include {error}. |
| crates/rustmail/src/i18n/language/en.rs | Adds EN strings for role add/remove outcomes; updates help + argument descriptions; updates Discord API error message to include {error}. |
| crates/rustmail/src/errors/dictionary.rs | Adds parameterized mappings for DiscordError::ApiError and CommandError::CommandFailed. |
| crates/rustmail/src/commands/remove_staff/text_command/remove_staff.rs | Refactors text remove-staff to accept user or role targets and handle role bulk removal + feedback. |
| crates/rustmail/src/commands/remove_staff/slash_command/remove_staff.rs | Refactors slash remove-staff to accept mentionable target and handle role bulk removal + followup messaging. |
| crates/rustmail/src/commands/remove_staff/common.rs | Adds RemoveRoleOutcome and bulk removal helper. |
| crates/rustmail/src/commands/add_staff/text_command/add_staff.rs | Refactors text add-staff to accept user or role targets and handle role bulk add + feedback. |
| crates/rustmail/src/commands/add_staff/slash_command/add_staff.rs | Refactors slash add-staff to accept mentionable target and handle role bulk add + followup messaging. |
| crates/rustmail/src/commands/add_staff/common.rs | Adds target parsing, guild role member resolution, and bulk add helper + max limit constant. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| params.insert("error".to_string(), msg.clone()); | ||
| ("discord.api_error".to_string(), Some(params)) | ||
| } | ||
| _ => ("discord.api_error".to_string(), None), |
| let members = guild_id.members(&ctx.http, None, None).await.map_err(|_| { | ||
| ModmailError::Discord(DiscordError::ApiError( | ||
| "Failed to fetch guild members".to_string(), | ||
| )) | ||
| })?; | ||
|
|
||
| Ok(members | ||
| .into_iter() | ||
| .filter(|m| m.roles.contains(&role_id)) | ||
| .map(|m| m.user.id) | ||
| .collect()) |
|
@copilot apply changes based on the comments in this thread |
…k arm Agent-Logs-Url: https://github.com/Rustmail/rustmail/sessions/458a29fb-da48-4a88-afea-b87c655158c6 Co-authored-by: Akinator31 <99099121+Akinator31@users.noreply.github.com>
…ith_role Agent-Logs-Url: https://github.com/Rustmail/rustmail/sessions/458a29fb-da48-4a88-afea-b87c655158c6 Co-authored-by: Akinator31 <99099121+Akinator31@users.noreply.github.com>
Applied both review fixes in commit
|
This pull request adds support for specifying either a user or a role when using the "add staff" and "remove staff" commands (both slash and text commands). This allows moderators to add or remove all members of a role to/from a thread at once, with appropriate validation and feedback. The implementation includes robust parsing, error handling, and limits to prevent abuse.
The most important changes are:
Add Staff Command Enhancements
AddTarget,AddTargetParse) and helper functions likeparse_add_target,members_with_role, andadd_role_members_to_channelincommon.rs. This enables adding all members of a role to a thread in one command, with a configurable maximum (MAX_ROLE_MEMBERS_PER_ADD).userorrole) as the target, with improved argument parsing and validation, and added user feedback for various scenarios (e.g., too many members, no members in role, forbidden roles).Remove Staff Command Enhancements
RemoveRoleOutcomeandremove_role_members_from_channel, mirroring the add staff improvements.