Skip to content

refactor(addmod): allow adding all users with a specific role - #404

Merged
Akinator31 merged 6 commits into
mainfrom
397-addrole-command
Apr 29, 2026
Merged

refactor(addmod): allow adding all users with a specific role#404
Akinator31 merged 6 commits into
mainfrom
397-addrole-command

Conversation

@Akinator31

Copy link
Copy Markdown
Member

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

  • Refactored the add staff logic to support both users and roles as targets, introducing new types (AddTarget, AddTargetParse) and helper functions like parse_add_target, members_with_role, and add_role_members_to_channel in common.rs. This enables adding all members of a role to a thread in one command, with a configurable maximum (MAX_ROLE_MEMBERS_PER_ADD).
  • Updated the slash command to accept a "mentionable" (user or role) 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).
  • Updated the text command to parse and resolve user or role IDs, fetch members for roles, and provide appropriate feedback and error handling.

Remove Staff Command Enhancements

  • Added support for removing all members of a role from a thread by introducing RemoveRoleOutcome and remove_role_members_from_channel, mirroring the add staff improvements.
  • Updated the remove staff slash command to accept a "mentionable" as the target, with corresponding argument and description changes.

@Akinator31
Akinator31 requested a review from Copilot April 29, 2026 15:27
@Akinator31 Akinator31 self-assigned this Apr 29, 2026
@Akinator31 Akinator31 linked an issue Apr 29, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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),
Comment on lines +70 to +80
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())
@Akinator31

Copy link
Copy Markdown
Member Author

@copilot apply changes based on the comments in this thread

Copilot AI commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

@copilot apply changes based on the comments in this thread

Applied both review fixes in commit 0b0271e:

  1. dictionary.rs:197 — Changed the catch-all _ arm to bind as err and populate the {error} param via err.to_string(), so ChannelCreationFailed, FailedToFetchCategories, and FailedToMoveChannel no longer surface the raw {error} placeholder token to users.

  2. common.rs:70-80 — Replaced the single-page guild_id.members(..., None, None) call with a paginated loop using a PAGE_LIMIT const (1000), an explicit early break on empty pages, and the last user ID as the after cursor — ensuring all guild members are fetched before filtering by role.

@Akinator31
Akinator31 merged commit 8f15f75 into main Apr 29, 2026
2 checks passed
@Akinator31
Akinator31 deleted the 397-addrole-command branch April 29, 2026 16:22
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.

addrole command

3 participants