diff options
| author | Nathan Perry <avaglir@gmail.com> | 2018-02-14 02:56:09 -0500 |
|---|---|---|
| committer | Nathan Perry <avaglir@gmail.com> | 2018-02-14 02:56:09 -0500 |
| commit | 49af4053df8e40d584c43f856e4d6bb3b8432698 (patch) | |
| tree | 31aec40e2bb26e59a486aa73f0aa02e3a8f39b95 | |
| parent | 0e30b074c1e27f11141ff6c74e6dc948a981603b (diff) | |
thulani leaves when he is done playing
| -rw-r--r-- | src/commands.rs | 20 | ||||
| -rw-r--r-- | src/util.rs | 14 |
2 files changed, 18 insertions, 16 deletions
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::<u64>("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"); diff --git a/src/util.rs b/src/util.rs index 54f10ee..4c59704 100644 --- a/src/util.rs +++ b/src/util.rs @@ -2,10 +2,6 @@ use std::env; use std::str::FromStr; use serenity::model::permissions::Permissions; -use serenity::model::id::GuildId; -use serenity::model::channel::Message; -use serenity::client::CACHE; - use url::Url; lazy_static! { @@ -36,13 +32,3 @@ pub fn must_env_lookup<T: FromStr>(s: &str) -> T { env::var(s).expect(&format!("missing env var {}", s)) .parse::<T>().unwrap_or_else(|_| panic!(format!("bad format for {}", s))) } - -pub trait GuildLookup { - fn guild_id(&self) -> Option<GuildId>; -} - -impl GuildLookup for Message { - fn guild_id(&self) -> Option<GuildId> { - CACHE.read().guild_channel(self.channel_id).map(|c| c.read().guild_id) - } -}
\ No newline at end of file |
