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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use crate::prelude::*;
use rive_models::{
    bot::{Bot, OwnedBot, OwnedBots, PublicBot},
    payload::{CreateBotPayload, EditBotPayload, InviteBotPayload},
};

impl Client {
    /// Create a new Revolt bot.
    pub async fn create_bot(&self, payload: CreateBotPayload) -> Result<Bot> {
        Ok(self
            .client
            .post(ep!(self, "/bots/create"))
            .json(&payload)
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }

    /// Fetch details of a public (or owned) bot by its id.
    pub async fn fetch_public_bot(&self, id: impl Into<String>) -> Result<PublicBot> {
        Ok(self
            .client
            .get(ep!(self, "/bots/{}/invite", id.into()))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }

    /// Invite a bot to a server or group by its id.
    pub async fn invite_bot(
        &self,
        bot_id: impl Into<String>,
        payload: InviteBotPayload,
    ) -> Result<()> {
        self.client
            .post(ep!(self, "/bots/{}/invite", bot_id.into()))
            .json(&payload)
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?;
        Ok(())
    }

    /// Fetch details of a bot you own by its id.
    pub async fn fetch_bot(&self, id: impl Into<String>) -> Result<OwnedBot> {
        Ok(self
            .client
            .get(ep!(self, "/bots/{}/invite", id.into()))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }

    /// Delete a bot by its id.
    pub async fn delete_bot(&self, id: impl Into<String>) -> Result<()> {
        self.client
            .delete(ep!(self, "/bots/{}", id.into()))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?;
        Ok(())
    }

    /// Edit bot details by its id.
    pub async fn edit_bot(&self, id: impl Into<String>, payload: EditBotPayload) -> Result<Bot> {
        Ok(self
            .client
            .patch(ep!(self, "/bots/{}", id.into()))
            .json(&payload)
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }

    /// Fetch all of the bots that you have control over.
    pub async fn fetch_owned_bots(&self) -> Result<OwnedBots> {
        Ok(self
            .client
            .get(ep!(self, "/bots/@me"))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?
            .json()
            .await?)
    }
}