From 5eea11a03c11551091b2c72f48590aec7f5410f0 Mon Sep 17 00:00:00 2001 From: Jokler Date: Mon, 3 Feb 2020 01:14:05 +0100 Subject: Add a json /api/bots endpoint for data retrieval --- src/bot/master.rs | 14 ++++++++++++++ src/bot/music.rs | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/bot') 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 { + 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 { 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 { } } -#[derive(Debug, PartialEq, Eq, Clone, Copy)] +#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize)] pub enum State { Playing, Paused, -- cgit v1.2.3-70-g09d2