From 1cc467ba28fd3269cc708d0481ca253f5c0a94fc Mon Sep 17 00:00:00 2001 From: Ethan Ruszanowski Date: Wed, 11 Jan 2023 17:46:58 -0500 Subject: [PATCH] Update commands --- src/commands/mod.rs | 2 +- src/commands/random.rs | 13 ++++++------- src/commands/slur.rs | 2 +- src/commands/team.rs | 19 +++++++++++++++++++ src/commands/team_up.rs | 17 ----------------- src/main.rs | 2 +- 6 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 src/commands/team.rs delete mode 100644 src/commands/team_up.rs diff --git a/src/commands/mod.rs b/src/commands/mod.rs index f947f1b..439df73 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,4 +1,4 @@ // Group all commands for registration pub(crate) mod slur; -pub(crate) mod team_up; +pub(crate) mod team; pub(crate) mod random; \ No newline at end of file diff --git a/src/commands/random.rs b/src/commands/random.rs index 59c3eb4..758eca3 100644 --- a/src/commands/random.rs +++ b/src/commands/random.rs @@ -1,16 +1,15 @@ use crate::{Context, Error}; /// Picks a random something -#[poise::command(slash_command, prefix_command, subcommands("god", "mode"))] +#[poise::command(slash_command, subcommands("god", "mode"))] pub(crate) async fn random( - ctx: Context<'_>, + _ctx: Context<'_>, ) -> Result<(), Error> { - ctx.say("Pick a subcommand, idiot.").await?; Ok(()) } -/// Picks a random god to play -#[poise::command(slash_command, prefix_command)] +/// Picks a random god +#[poise::command(slash_command)] pub(crate) async fn god( ctx: Context<'_>, ) -> Result<(), Error> { @@ -18,8 +17,8 @@ pub(crate) async fn god( Ok(()) } -/// Picks a random mode to play -#[poise::command(slash_command, prefix_command)] +/// Picks a random mode +#[poise::command(slash_command)] pub(crate) async fn mode( ctx: Context<'_>, ) -> Result<(), Error> { diff --git a/src/commands/slur.rs b/src/commands/slur.rs index ffcba29..6b5a921 100644 --- a/src/commands/slur.rs +++ b/src/commands/slur.rs @@ -7,7 +7,7 @@ use std::{ }; /// Basically a ping command -#[poise::command(slash_command, prefix_command)] +#[poise::command(slash_command)] pub(crate) async fn slur( ctx: Context<'_>, ) -> Result<(), Error> { diff --git a/src/commands/team.rs b/src/commands/team.rs new file mode 100644 index 0000000..cea5ba5 --- /dev/null +++ b/src/commands/team.rs @@ -0,0 +1,19 @@ +use crate::{Context, Error}; +use crate::serenity; + +/// Splits up players for custom matches +#[poise::command(slash_command)] +pub(crate) async fn team( + ctx: Context<'_>, + #[description = "Your voice channel"] + #[channel_types("Voice")] channel: serenity::Channel, + #[description = "Team size"] + #[min = 1] size: u8, +) -> Result<(), Error> { + let mut v = ctx.guild().unwrap().voice_states; // Get hashmap of users' voice states within the guild + v.retain(|_, s| s.channel_id == Some(channel.id())); // Drop users not active in requested voice channel from hashmap + let res = format!("Channel {} has {} active users. Team size is {}.", channel.id(), v.keys().len(), size); + + ctx.say(res).await?; + Ok(()) +} diff --git a/src/commands/team_up.rs b/src/commands/team_up.rs deleted file mode 100644 index abdf18d..0000000 --- a/src/commands/team_up.rs +++ /dev/null @@ -1,17 +0,0 @@ -use crate::{Context, Error}; -use crate::serenity; - -/// Split up users for custom joust matches -#[poise::command(slash_command, prefix_command)] -pub(crate) async fn team_up( - ctx: Context<'_>, - #[description = "Your voice channel"] channel: Option, -) -> Result<(), Error> { - let c = channel.as_ref().unwrap(); // Get channel info from object - let mut v = ctx.guild().unwrap().voice_states; // Get hashmap of users' voice states within the guild - v.retain(|_, s| s.channel_id == Some(c.id())); // Drop users not active in requested voice channel from hashmap - let res = format!("Channel {} has {} active users", c.id(), v.keys().len()); - - ctx.say(res).await?; - Ok(()) -} diff --git a/src/main.rs b/src/main.rs index 9e6b027..5e784af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ async fn main() { .options(poise::FrameworkOptions { commands: vec![ commands::slur::slur(), - commands::team_up::team_up(), + commands::team::team(), commands::random::random(), ], // IntelliJ doesn't like this, but it's fine. ..Default::default()