Update commands

This commit is contained in:
Em (Ethan) Ruszanowski 2023-01-11 17:46:58 -05:00
parent a2e7d6f531
commit 1cc467ba28
No known key found for this signature in database
GPG key ID: C3E7A3C0B1491DFE
6 changed files with 28 additions and 27 deletions

View file

@ -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;

View file

@ -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> {

View file

@ -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> {

19
src/commands/team.rs Normal file
View file

@ -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(())
}

View file

@ -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<serenity::Channel>,
) -> 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(())
}

View file

@ -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()