aboutsummaryrefslogtreecommitdiffstats
path: root/src/bot/music.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bot/music.rs')
-rw-r--r--src/bot/music.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/bot/music.rs b/src/bot/music.rs
index 920f1cb..d53e4a8 100644
--- a/src/bot/music.rs
+++ b/src/bot/music.rs
@@ -44,7 +44,7 @@ fn parse_seek(mut amount: &str) -> Result<Seek, ()> {
}
}
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum State {
Playing,
Paused,
@@ -52,6 +52,18 @@ pub enum State {
EndOfStream,
}
+impl std::fmt::Display for State {
+ fn fmt(&self, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+ match self {
+ State::Playing => write!(fmt, "Playing"),
+ State::Paused => write!(fmt, "Paused"),
+ State::Stopped | State::EndOfStream => write!(fmt, "Stopped"),
+ }?;
+
+ Ok(())
+ }
+}
+
#[derive(Debug)]
pub enum MusicBotMessage {
TextMessage(Message),
@@ -176,7 +188,7 @@ impl MusicBot {
self.send_message(&format!("Playing {}", ts::underline(&metadata.title)));
self.set_description(&format!("Currently playing '{}'", metadata.title));
self.player.reset().unwrap();
- self.player.set_source_url(metadata.url).unwrap();
+ self.player.set_metadata(metadata).unwrap();
self.player.play().unwrap();
}
@@ -211,6 +223,22 @@ impl MusicBot {
&self.name
}
+ pub fn state(&self) -> State {
+ *self.state.read().expect("RwLock was not poisoned")
+ }
+
+ pub fn volume(&self) -> f64 {
+ self.player.volume()
+ }
+
+ pub fn currently_playing(&self) -> Option<AudioMetadata> {
+ self.player.currently_playing()
+ }
+
+ pub fn playlist_to_vec(&self) -> Vec<AudioMetadata> {
+ self.playlist.read().unwrap().to_vec()
+ }
+
pub fn my_channel(&self) -> ChannelId {
self.teamspeak
.as_ref()