aboutsummaryrefslogtreecommitdiff
path: root/src/audio/mod.rs
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2019-11-17 21:31:28 -0500
committerNathan Perry <np@nathanperry.dev>2019-11-17 21:31:28 -0500
commit2a38c282dd57c2051a568549d62c80d6036e8920 (patch)
treeec25f84dda5cdb100ae093b0a690ef349636b4dc /src/audio/mod.rs
parent479bb8d584b138054acc6567b72cb3076832e79c (diff)
most restructuring done
Diffstat (limited to 'src/audio/mod.rs')
-rw-r--r--src/audio/mod.rs37
1 files changed, 4 insertions, 33 deletions
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<bool>;
-}
-
-impl CtxExt for Context {
- fn currently_playing(&self) -> bool {
- let queue_lock = self.data.lock().get::<PlayQueue>().cloned().unwrap();
- let play_queue = queue_lock.read().unwrap();
- play_queue.playing.is_some()
- }
-
- fn users_listening(&self) -> Result<bool> {
- let channel_id = ChannelId(must_env_lookup::<u64>("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::<VoiceManager>(Arc::clone(&c.voice_manager));
}
}