From 4e1c2b9f04073294ecb8402486c20d9c01721598 Mon Sep 17 00:00:00 2001 From: Jokler Date: Wed, 14 Oct 2020 00:19:27 +0200 Subject: Replace channels&locks with actors & log with slog --- src/web_server/bot_data.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/web_server/bot_data.rs (limited to 'src/web_server/bot_data.rs') diff --git a/src/web_server/bot_data.rs b/src/web_server/bot_data.rs new file mode 100644 index 0000000..af0c5e1 --- /dev/null +++ b/src/web_server/bot_data.rs @@ -0,0 +1,47 @@ +use async_trait::async_trait; + +use xtra::{Context, Handler, Message}; + +use crate::bot::MasterBot; +use crate::web_server::BotData; + +pub struct BotNameListRequest; + +impl Message for BotNameListRequest { + type Result = Vec; +} + +#[async_trait] +impl Handler for MasterBot { + async fn handle(&mut self, _: BotNameListRequest, _: &mut Context) -> Vec { + self.bot_names() + } +} + +pub struct BotDataListRequest; + +impl Message for BotDataListRequest { + type Result = Vec; +} + +#[async_trait] +impl Handler for MasterBot { + async fn handle(&mut self, _: BotDataListRequest, _: &mut Context) -> Vec { + self.bot_datas().await + } +} + +pub struct BotDataRequest(pub String); + +impl Message for BotDataRequest { + type Result = Option; +} + +#[async_trait] +impl Handler for MasterBot { + async fn handle(&mut self, r: BotDataRequest, _: &mut Context) -> Option { + let name = r.0; + + self.bot_data(name).await + } +} -- cgit v1.2.3-70-g09d2