aboutsummaryrefslogtreecommitdiffstats
path: root/src/web_server/bot_data.rs
blob: af0c5e19b98b9880c448ca16490ee8a13a7aed0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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<String>;
}

#[async_trait]
impl Handler<BotNameListRequest> for MasterBot {
    async fn handle(&mut self, _: BotNameListRequest, _: &mut Context<Self>) -> Vec<String> {
        self.bot_names()
    }
}

pub struct BotDataListRequest;

impl Message for BotDataListRequest {
    type Result = Vec<BotData>;
}

#[async_trait]
impl Handler<BotDataListRequest> for MasterBot {
    async fn handle(&mut self, _: BotDataListRequest, _: &mut Context<Self>) -> Vec<BotData> {
        self.bot_datas().await
    }
}

pub struct BotDataRequest(pub String);

impl Message for BotDataRequest {
    type Result = Option<BotData>;
}

#[async_trait]
impl Handler<BotDataRequest> for MasterBot {
    async fn handle(&mut self, r: BotDataRequest, _: &mut Context<Self>) -> Option<BotData> {
        let name = r.0;

        self.bot_data(name).await
    }
}