From 29dd3532bb45206fb82ae97e4a26694fca7d63ca Mon Sep 17 00:00:00 2001 From: jellywx Date: Sat, 10 Apr 2021 23:50:44 +0100 Subject: [PATCH] stop command now just stops audio. cleaned some code --- Cargo.lock | 2 +- src/main.rs | 33 ++++++++++++++------------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 308622c..afe6111 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1838,7 +1838,7 @@ dependencies = [ [[package]] name = "soundfx-rs" -version = "1.2.1" +version = "1.2.2" dependencies = [ "dashmap", "dotenv", diff --git a/src/main.rs b/src/main.rs index ff6377b..fa35a16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -289,33 +289,23 @@ async fn join_channel( let call_opt = songbird.get(guild.id); if let Some(call) = call_opt { - { - // set call to deafen - let _ = call.lock().await.deafen(true).await; - } - (call, Ok(())) } else { let (call, res) = songbird.join(guild.id, channel_id).await; - { - // set call to deafen - let _ = call.lock().await.deafen(true).await; - } - (call, res) } } else { let (call, res) = songbird.join(guild.id, channel_id).await; - { - // set call to deafen - let _ = call.lock().await.deafen(true).await; - } - (call, res) }; + { + // set call to deafen + let _ = call.lock().await.deafen(true).await; + } + (call, res) } @@ -767,9 +757,9 @@ __Available ambience sounds:__ #[command] #[permission_level(Managed)] async fn stop_playing(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { - { - let guild_id = msg.guild_id.unwrap(); + let guild_id = msg.guild_id.unwrap(); + { let track_count = ctx .data .read() @@ -782,9 +772,14 @@ async fn stop_playing(ctx: &Context, msg: &Message, _args: Args) -> CommandResul write_lock.insert(guild_id, 0); } - let voice_manager = songbird::get(ctx).await.unwrap(); + let songbird = songbird::get(ctx).await.unwrap(); + let call_opt = songbird.get(guild_id); - let _ = voice_manager.leave(msg.guild_id.unwrap()).await; + if let Some(call) = call_opt { + let mut lock = call.lock().await; + + lock.stop(); + } Ok(()) }