aboutsummaryrefslogtreecommitdiffstats
path: root/src/bot
diff options
context:
space:
mode:
authorJokler <jokler@protonmail.com>2020-02-03 01:14:05 +0100
committerJokler <jokler@protonmail.com>2020-02-22 23:20:10 +0100
commit5eea11a03c11551091b2c72f48590aec7f5410f0 (patch)
tree4767841f341b82539c2586ef04e67fe72e52bd4b /src/bot
parent2831c2b60cb61a14c7efee4ab5c0389eb3ad5469 (diff)
downloadpokebot-5eea11a03c11551091b2c72f48590aec7f5410f0.tar.gz
pokebot-5eea11a03c11551091b2c72f48590aec7f5410f0.zip
Add a json /api/bots endpoint for data retrieval
Diffstat (limited to 'src/bot')
-rw-r--r--src/bot/master.rs14
-rw-r--r--src/bot/music.rs3
2 files changed, 16 insertions, 1 deletions
diff --git a/src/bot/master.rs b/src/bot/master.rs
index 10a7572..67867ef 100644
--- a/src/bot/master.rs
+++ b/src/bot/master.rs
@@ -213,6 +213,20 @@ impl MasterBot {
Ok(())
}
+ pub fn bot_data(&self, name: String) -> Option<crate::web_server::BotData> {
+ let music_bots = self.music_bots.read().unwrap();
+
+ let bot = music_bots.connected_bots.get(&name)?;
+
+ Some(crate::web_server::BotData {
+ name: name,
+ state: bot.state(),
+ volume: bot.volume(),
+ currently_playing: bot.currently_playing(),
+ playlist: bot.playlist_to_vec(),
+ })
+ }
+
pub fn bot_datas(&self) -> Vec<crate::web_server::BotData> {
let music_bots = self.music_bots.read().unwrap();
diff --git a/src/bot/music.rs b/src/bot/music.rs
index d53e4a8..0def280 100644
--- a/src/bot/music.rs
+++ b/src/bot/music.rs
@@ -5,6 +5,7 @@ use std::thread;
use humantime;
use log::{debug, info};
+use serde::Serialize;
use structopt::StructOpt;
use tokio02::sync::mpsc::UnboundedSender;
use tsclientlib::{data, ChannelId, ClientId, ConnectOptions, Identity, Invoker, MessageTarget};
@@ -44,7 +45,7 @@ fn parse_seek(mut amount: &str) -> Result<Seek, ()> {
}
}
-#[derive(Debug, PartialEq, Eq, Clone, Copy)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize)]
pub enum State {
Playing,
Paused,