use crate::prelude::*;
use rive_models::{
bot::{Bot, OwnedBot, OwnedBots, PublicBot},
data::{CreateBotData, EditBotData, InviteBotData},
};
impl Client {
pub async fn create_bot(&self, data: CreateBotData) -> Result<Bot> {
Ok(self
.client
.post(ep!(self, "/bots/create"))
.json(&data)
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
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?)
}
pub async fn invite_bot(&self, bot_id: impl Into<String>, data: InviteBotData) -> Result<()> {
self.client
.post(ep!(self, "/bots/{}/invite", bot_id.into()))
.json(&data)
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?;
Ok(())
}
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?)
}
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(())
}
pub async fn edit_bot(&self, id: impl Into<String>, data: EditBotData) -> Result<Bot> {
Ok(self
.client
.patch(ep!(self, "/bots/{}", id.into()))
.json(&data)
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
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?)
}
}