diff --git a/cmds/src/dispatch.rs b/cmds/src/dispatch.rs index 566c345..815cffc 100644 --- a/cmds/src/dispatch.rs +++ b/cmds/src/dispatch.rs @@ -1,3 +1,8 @@ +mod ilo; +mod midi; +mod status; +mod uptime; + use kon_libs::{ KonData, KonError, @@ -5,13 +10,6 @@ use kon_libs::{ PoiseCtx }; -use poise::Command; - -mod ilo; -mod midi; -mod status; -mod uptime; - use { ilo::ilo, midi::midi_to_wav, @@ -25,7 +23,7 @@ macro_rules! commands { } } -pub fn register_cmds() -> Vec> { commands!(deploy, ping, midi_to_wav, status, ilo, uptime) } +pub fn register_cmds() -> Vec> { commands!(deploy, ping, ilo, midi_to_wav, status, uptime) } /// Deploy the commands globally or in a guild #[poise::command(prefix_command, owners_only, guild_only)] @@ -35,7 +33,7 @@ pub async fn deploy(ctx: PoiseCtx<'_>) -> KonResult<()> { } /// Check if the bot is alive -#[poise::command(slash_command)] +#[poise::command(slash_command, install_context = "Guild|User", interaction_context = "Guild|BotDm|PrivateChannel")] pub async fn ping(ctx: PoiseCtx<'_>) -> KonResult<()> { ctx.reply(format!("Powong! `{:.2?}`", ctx.ping().await)).await?; Ok(()) diff --git a/cmds/src/dispatch/midi.rs b/cmds/src/dispatch/midi.rs index 7c969d0..c4d833f 100644 --- a/cmds/src/dispatch/midi.rs +++ b/cmds/src/dispatch/midi.rs @@ -7,7 +7,10 @@ use { }, poise::{ CreateReply, - serenity_prelude::CreateAttachment + serenity_prelude::{ + CreateAttachment, + Message + } }, regex::Regex, std::{ @@ -23,12 +26,12 @@ use { /// Convert MIDI file to WAV #[poise::command( context_menu_command = "MIDI -> WAV", - install_context = "User", + install_context = "Guild|User", interaction_context = "Guild|BotDm|PrivateChannel" )] pub async fn midi_to_wav( ctx: super::PoiseCtx<'_>, - #[description = "MIDI file to be converted"] message: poise::serenity_prelude::Message + #[description = "MIDI file to be converted"] message: Message ) -> KonResult<()> { let re = Regex::new(r"(?i)\.mid$").unwrap(); @@ -87,9 +90,12 @@ pub async fn midi_to_wav( &*wav_path, format_bytes(metadata(&*wav_path).unwrap().size()) ))) - .await - .unwrap(); + .await?; } else if reply.is_ok() { + println!( + "Discord[{}]: Processed file uploaded back to Discord channel", + ctx.command().qualified_name + ); remove_file(midi_path)?; remove_file(&*wav_path)?; } @@ -97,8 +103,7 @@ pub async fn midi_to_wav( Err(y) => { ctx .send(CreateReply::default().content("Command didn't execute successfully, check console for more information!")) - .await - .unwrap(); + .await?; return Err(KonError::from(format!("Midi conversion failed: {y}"))) } diff --git a/cmds/src/dispatch/status.rs b/cmds/src/dispatch/status.rs index b4ebd21..5bbc906 100644 --- a/cmds/src/dispatch/status.rs +++ b/cmds/src/dispatch/status.rs @@ -73,7 +73,12 @@ fn process_pms_statuses(servers: Vec<(String, Vec)>) -> Vec<(String, Stri } /// Query the server statuses -#[poise::command(slash_command, subcommands("wg"))] +#[poise::command( + slash_command, + install_context = "Guild|User", + interaction_context = "Guild|BotDm|PrivateChannel", + subcommands("wg") +)] pub async fn status(_: super::PoiseCtx<'_>) -> KonResult<()> { Ok(()) } /// Retrieve the server statuses from Wargaming diff --git a/cmds/src/dispatch/uptime.rs b/cmds/src/dispatch/uptime.rs index 3ee1cb7..2ae85c8 100644 --- a/cmds/src/dispatch/uptime.rs +++ b/cmds/src/dispatch/uptime.rs @@ -46,7 +46,7 @@ fn get_os_info() -> String { } /// Retrieve host and bot uptimes -#[poise::command(slash_command)] +#[poise::command(slash_command, install_context = "Guild|User", interaction_context = "Guild|BotDm|PrivateChannel")] pub async fn uptime(ctx: super::PoiseCtx<'_>) -> KonResult<()> { let bot = ctx.http().get_current_user().await.unwrap(); let mut sys = System::new_all();