Skip to content

feat: add command to ping random members#103

Open
AnandajithS wants to merge 1 commit intoamfoss:developfrom
AnandajithS:random_command
Open

feat: add command to ping random members#103
AnandajithS wants to merge 1 commit intoamfoss:developfrom
AnandajithS:random_command

Conversation

@AnandajithS
Copy link
Contributor

This PR adds a $random command which randomly selects and pings 5 members who are either First Years or Second Years

Changes

  • Added a new file random.rs which contains the implementation of the $random command
  • Added the command in commands/mod.rs
  • Added a new dependency rand which provides the .shuffle method

Copilot AI review requested due to automatic review settings March 9, 2026 16:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new $random prefix command to ping a random subset of members with either the First Year or Second Year role, wiring it into the bot’s command registry and introducing a rand dependency.

Changes:

  • Added $random command implementation to fetch guild members, filter by year roles, and ping 5 selected members.
  • Registered the new command in src/commands/mod.rs.
  • Added role ID constants for First/Second Year and added rand as a dependency.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/ids.rs Adds role ID constants for First/Second Year filtering.
src/commands/random.rs Implements $random member selection and ping message.
src/commands/mod.rs Registers the new random command in the command list.
Cargo.toml Adds direct rand dependency.
Cargo.lock Records rand addition and multiple dependency updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +9
#[poise::command(prefix_command)]
pub async fn random(ctx: Context<'_>) -> Result<(), Error> {
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

$random pings 5 users and is currently callable by anyone. To prevent abuse/spam, consider restricting it (e.g., owners_only or check = "is_privileged") and/or adding a per-user cooldown.

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +29
let ping_message = selected
.iter()
.map(|m| m.user.mention().to_string())
.collect::<Vec<_>>()
.join("\n");

ctx.say(format!("Pinging 5 members: {}", ping_message))
.await?;
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The response text always says "Pinging 5 members" even if fewer than 5 eligible members exist (or if selection returns fewer for any reason), which can produce misleading output and an empty message body. Use selected.len() in the message and handle the zero-selected case with a friendly reply.

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +19
.filter(|m| {
!m.user.bot
&& (m.roles.contains(&RoleId::new(FIRST_YEAR_ROLE_ID))
|| m.roles.contains(&RoleId::new(SECOND_YEAR_ROLE_ID)))
})
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The role IDs are converted to RoleId inside the filter closure for every member. Hoist let first_year = RoleId::new(...); let second_year = ...; outside the iterator to avoid repeated construction and keep the filter easier to read.

Copilot uses AI. Check for mistakes.
mailparse = "0.15"
html2text = "0.12" No newline at end of file
html2text = "0.12"
rand = "0.10" No newline at end of file
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

Adding rand = "0.10" introduces a second major rand version in the build (Cargo.lock now contains both rand 0.8.5 and rand 0.10.0). If you don’t need 0.10-specific APIs, prefer aligning to the existing rand 0.8.x to reduce compile time and binary size; otherwise consider documenting why 0.10 is required.

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +12
let guild = ctx.guild_id().ok_or("No guild id")?;
let members = guild.members(ctx.http(), None, None).await?;

Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

This command bulk-fetches the guild member list via the REST API (GuildId::members). Discord restricts this endpoint and it can fail (or return partial data) unless the application has the Guild Members privileged intent enabled; it’s also potentially expensive on larger guilds. Consider either enabling/requesting the needed intent and using a paginated/streaming approach, or refactoring to avoid full member enumeration if possible.

Copilot uses AI. Check for mistakes.
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.

2 participants