From 49af4053df8e40d584c43f856e4d6bb3b8432698 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Wed, 14 Feb 2018 02:56:09 -0500 Subject: thulani leaves when he is done playing --- src/commands.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/commands.rs') diff --git a/src/commands.rs b/src/commands.rs index 83eba45..952a41a 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -76,7 +76,23 @@ impl PlayQueue { let allow_continue = queue.playing.clone().map_or(false, |x| !x.audio.lock().finished); - if allow_continue || queue.queue.is_empty() { + if allow_continue { + sleep(); + continue; + } + + if queue.queue.is_empty() { + if queue.playing.is_some() { // must be finished + assert!({ + let audio_lck = queue.playing.clone().unwrap().audio; + let audio = audio_lck.lock(); + audio.finished + }); + + let mut manager = voice_manager.lock(); + manager.leave(*TARGET_GUILD_ID); + } + sleep(); continue; } @@ -93,7 +109,6 @@ impl PlayQueue { }; let mut manager = voice_manager.lock(); - let handler = manager.join(*TARGET_GUILD_ID, must_env_lookup::("VOICE_CHANNEL")); match handler { @@ -269,6 +284,7 @@ command!(die(ctx, msg) { if let Some(handler) = manager.get_mut(*TARGET_GUILD_ID) { handler.stop(); + handler.leave(); } else { send(msg.channel_id, "YOU die", msg.tts)?; debug!("got die with no handler attached"); -- cgit v1.3.1