aboutsummaryrefslogtreecommitdiffstats
path: root/src/bot
diff options
context:
space:
mode:
authorJokler <jokler@protonmail.com>2020-02-02 19:50:33 +0100
committerJokler <jokler@protonmail.com>2020-02-22 23:20:10 +0100
commit2831c2b60cb61a14c7efee4ab5c0389eb3ad5469 (patch)
tree835f1abad6e234f6d74d4be999f690709954be89 /src/bot
parentca4c0158f417b87f04313053a3f656f2de4e803b (diff)
downloadpokebot-2831c2b60cb61a14c7efee4ab5c0389eb3ad5469.tar.gz
pokebot-2831c2b60cb61a14c7efee4ab5c0389eb3ad5469.zip
Add a very basic template using available info
Diffstat (limited to 'src/bot')
-rw-r--r--src/bot/master.rs22
-rw-r--r--src/bot/music.rs32
2 files changed, 46 insertions, 8 deletions
diff --git a/src/bot/master.rs b/src/bot/master.rs
index bc38cca..10a7572 100644
--- a/src/bot/master.rs
+++ b/src/bot/master.rs
@@ -213,14 +213,24 @@ impl MasterBot {
Ok(())
}
- pub fn names(&self) -> Vec<String> {
+ pub fn bot_datas(&self) -> Vec<crate::web_server::BotData> {
let music_bots = self.music_bots.read().unwrap();
- music_bots
- .connected_bots
- .iter()
- .map(|(_, b)| b.name().to_owned())
- .collect()
+ let len = music_bots.connected_bots.len();
+ let mut result = Vec::with_capacity(len);
+ for (name, bot) in &music_bots.connected_bots {
+ let bot_data = crate::web_server::BotData {
+ name: name.clone(),
+ state: bot.state(),
+ volume: bot.volume(),
+ currently_playing: bot.currently_playing(),
+ playlist: bot.playlist_to_vec(),
+ };
+
+ result.push(bot_data);
+ }
+
+ result
}
pub fn quit(&self, reason: String) {
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()