diff --git a/src/commands/command_helper.rs b/src/commands/command_helper.rs new file mode 100644 index 0000000..18a1dde --- /dev/null +++ b/src/commands/command_helper.rs @@ -0,0 +1,38 @@ +use std::time::Duration; +use crate::{Context, Error}; + +pub(crate) async fn send( + ctx: Context<'_>, + reply: String +) -> Result<(), Error> { + if let Err(why) = ctx + .send(|m| { + m.content(reply) + .allowed_mentions(|am| am.parse(serenity::builder::ParseValue::Roles)) + }) + .await + { + println!("Error sending message: {:?}", why) + } + Ok(()) +} + +pub(crate) fn cooldown( + ctx: &Context, + user: u64, + global: u64 +) -> Option> { + let mut cooldown_tracker = ctx.command().cooldowns.lock().unwrap(); + let mut cooldown_durations = poise::CooldownConfig::default(); + cooldown_durations.user = Some(Duration::from_secs(user)); + cooldown_durations.global = Some(Duration::from_secs(global)); + + match cooldown_tracker.remaining_cooldown_2(*ctx, &cooldown_durations) { + Some(remaining) => + Some(Err(format!("Please wait {} seconds", remaining.as_secs()).into())), + None => { + cooldown_tracker.start_cooldown(*ctx); + None + } + } +} \ No newline at end of file diff --git a/src/commands/helpstart.rs b/src/commands/helpstart.rs new file mode 100644 index 0000000..bd89c72 --- /dev/null +++ b/src/commands/helpstart.rs @@ -0,0 +1,27 @@ +use crate::{Context, Error}; +use crate::commands::command_helper; + +#[poise::command(slash_command)] +pub(crate) async fn helpstart( + ctx: Context<'_>, + + #[min = 1_u8] + #[max = 3_u8] + #[description = "default: 3"] + #[rename = "needed"] + needed_players: u8 +) -> Result<(), Error> { + if let Some(value) = command_helper::cooldown( + &ctx, + 1200, + 600 + ) { + return value; + } + let reply = format!( + "<@&1008075054971621448>\nneed: {}" + ,needed_players + ); + + command_helper::send(ctx, reply).await +} \ No newline at end of file diff --git a/src/commands/lfg.rs b/src/commands/lfg.rs index 8a19b5a..746d0c1 100644 --- a/src/commands/lfg.rs +++ b/src/commands/lfg.rs @@ -1,4 +1,3 @@ -use std::time::Duration; // use crate::commands::lfg::Difficulty::Normal; use crate::commands::lfg::Map::*; @@ -9,6 +8,7 @@ use crate::{Context, Error}; use serenity::model::id::RoleId; use serenity::model::mention::Mention; use serenity::model::mention::Mention::Role; +use crate::commands::command_helper; #[derive(Debug, poise::ChoiceParameter, PartialEq)] pub enum Map { @@ -27,6 +27,8 @@ pub enum Mode { Speedrun, #[name = "Challenge"] Challenge, + #[name = "Event/Challenge"] + Event, } #[derive(Debug, poise::ChoiceParameter)] pub enum Difficulty { @@ -49,7 +51,7 @@ pub(crate) async fn lfg( #[rename = "mode"] #[description = "play-style"] - mode: Option, + mode: Mode, #[min = 1_u8] #[max = 3_u8] @@ -68,28 +70,13 @@ pub(crate) async fn lfg( note: Option, ) -> Result<(), Error> { - { - let mut cooldown_tracker = ctx.command().cooldowns.lock().unwrap(); - let mut cooldown_durations = poise::CooldownConfig::default(); - cooldown_durations.user = Some(Duration::from_secs(600)); - - match cooldown_tracker.remaining_cooldown_2(ctx, &cooldown_durations) { - Some(remaining) => { - return Err(format!("Please wait {} seconds", remaining.as_secs()).into()) - } - None => cooldown_tracker.start_cooldown(ctx), - } - }; - - - - - - - - - - + if let Some(value) = command_helper::cooldown( + &ctx, + 600, + 300 + ) { + return value; + } @@ -98,7 +85,7 @@ pub(crate) async fn lfg( if current >= desired { desired = 4 } let map_name: &str = map.name(); let ping: Mention; - match mode.unwrap_or(Casual) { + match mode { Casual => match map { DeadEnd => ping = Role(RoleId(1005837123921915914)), BadBlood => ping = Role(RoleId(1140190470698438666)), @@ -106,6 +93,7 @@ pub(crate) async fn lfg( }, Speedrun => ping = Role(RoleId(1005836989595144243)), Challenge => ping = Role(RoleId(1005836864680361994)), + Event => ping = Role(RoleId(1175116511095050331)) } let diff_name: &str = if map != AlienArcadium { difficulty.unwrap_or(Normal).name() @@ -135,15 +123,5 @@ pub(crate) async fn lfg( } - - if let Err(why) = ctx - .send(|m| { - m.content(reply) - .allowed_mentions(|am| am.parse(serenity::builder::ParseValue::Roles)) - }) - .await - { - println!("Error sending message: {:?}", why) - } - Ok(()) + command_helper::send(ctx, reply).await } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 5bd5535..bef877a 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,2 +1,5 @@ pub(crate) mod lfg; pub(crate) mod xd; +pub(crate) mod helpstart; +mod command_helper; +