aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commands.rs20
-rw-r--r--src/util.rs14
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