From 2a38c282dd57c2051a568549d62c80d6036e8920 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Sun, 17 Nov 2019 21:31:28 -0500 Subject: most restructuring done --- src/audio/mod.rs | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) (limited to 'src/audio/mod.rs') diff --git a/src/audio/mod.rs b/src/audio/mod.rs index 5044c49..3c3041f 100644 --- a/src/audio/mod.rs +++ b/src/audio/mod.rs @@ -5,18 +5,15 @@ use either::Either; use serenity::{ client::bridge::voice::ClientVoiceManager, model::{ - id::ChannelId, + id::{ + ChannelId, + }, }, prelude::*, voice::LockedAudio, }; use typemap::Key; -use crate::{ - must_env_lookup, - Result, -}; - pub use self::play_queue::PlayQueue; pub use self::timeutil::parse_times; pub use self::ytdl::*; @@ -25,32 +22,6 @@ mod timeutil; mod ytdl; mod play_queue; -pub trait CtxExt { - fn currently_playing(&self) -> bool; - fn users_listening(&self) -> Result; -} - -impl CtxExt for Context { - fn currently_playing(&self) -> bool { - let queue_lock = self.data.lock().get::().cloned().unwrap(); - let play_queue = queue_lock.read().unwrap(); - play_queue.playing.is_some() - } - - fn users_listening(&self) -> Result { - let channel_id = ChannelId(must_env_lookup::("VOICE_CHANNEL")); - let channel = channel_id.to_channel()?; - let res = channel.guild() - .and_then(|ch| ch.read().guild()) - .map(|g| (&g.read().voice_states) - .into_iter() - .any(|(_, state)| state.channel_id == Some(channel_id))) - .unwrap_or(false); - - Ok(res) - } -} - pub struct VoiceManager; impl Key for VoiceManager { @@ -59,7 +30,7 @@ impl Key for VoiceManager { impl VoiceManager { pub fn register(c: &mut Client) { - let mut data = c.data.lock(); + let mut data = c.data.write(); data.insert::(Arc::clone(&c.voice_manager)); } } -- cgit v1.3.1