1use crate::prelude::*;
2use rive_models::{
3 bot::{Bot, OwnedBot, OwnedBots, PublicBot},
4 data::{CreateBotData, EditBotData, InviteBotData},
5};
6
7impl Client {
8 pub async fn create_bot(&self, data: CreateBotData) -> Result<Bot> {
10 Ok(self
11 .client
12 .post(ep!(self, "/bots/create"))
13 .json(&data)
14 .auth(&self.authentication)
15 .send()
16 .await?
17 .process_error()
18 .await?
19 .json()
20 .await?)
21 }
22
23 pub async fn fetch_public_bot(&self, id: impl Into<String>) -> Result<PublicBot> {
25 Ok(self
26 .client
27 .get(ep!(self, "/bots/{}/invite", id.into()))
28 .auth(&self.authentication)
29 .send()
30 .await?
31 .process_error()
32 .await?
33 .json()
34 .await?)
35 }
36
37 pub async fn invite_bot(&self, bot_id: impl Into<String>, data: InviteBotData) -> Result<()> {
39 self.client
40 .post(ep!(self, "/bots/{}/invite", bot_id.into()))
41 .json(&data)
42 .auth(&self.authentication)
43 .send()
44 .await?
45 .process_error()
46 .await?;
47 Ok(())
48 }
49
50 pub async fn fetch_bot(&self, id: impl Into<String>) -> Result<OwnedBot> {
52 Ok(self
53 .client
54 .get(ep!(self, "/bots/{}/invite", id.into()))
55 .auth(&self.authentication)
56 .send()
57 .await?
58 .process_error()
59 .await?
60 .json()
61 .await?)
62 }
63
64 pub async fn delete_bot(&self, id: impl Into<String>) -> Result<()> {
66 self.client
67 .delete(ep!(self, "/bots/{}", id.into()))
68 .auth(&self.authentication)
69 .send()
70 .await?
71 .process_error()
72 .await?;
73 Ok(())
74 }
75
76 pub async fn edit_bot(&self, id: impl Into<String>, data: EditBotData) -> Result<Bot> {
78 Ok(self
79 .client
80 .patch(ep!(self, "/bots/{}", id.into()))
81 .json(&data)
82 .auth(&self.authentication)
83 .send()
84 .await?
85 .process_error()
86 .await?
87 .json()
88 .await?)
89 }
90
91 pub async fn fetch_owned_bots(&self) -> Result<OwnedBots> {
93 Ok(self
94 .client
95 .get(ep!(self, "/bots/@me"))
96 .auth(&self.authentication)
97 .send()
98 .await?
99 .process_error()
100 .await?
101 .json()
102 .await?)
103 }
104}