use reqwest::Client;
use serde_json::to_string;
use crate::errors::ChorusResult;
use crate::instance::ChorusUser;
use crate::ratelimiter::ChorusRequest;
use crate::types::{
AcceptInviteSchema, CreateChannelInviteSchema, GuildInvite, Invite, LimitType, Snowflake,
};
impl ChorusUser {
pub async fn accept_invite(
&mut self,
invite_code: &str,
session_id: Option<String>,
) -> ChorusResult<Invite> {
let request = ChorusRequest {
request: Client::new()
.post(format!(
"{}/invites/{}",
self.belongs_to.read().unwrap().urls.api,
invite_code
))
.json(&AcceptInviteSchema { session_id }),
limit_type: LimitType::Global,
}
.with_headers_for(self);
request.send_and_deserialize_response::<Invite>(self).await
}
pub async fn create_user_invite(&mut self, code: Option<&str>) -> ChorusResult<Invite> {
ChorusRequest {
request: Client::new()
.post(format!(
"{}/users/@me/invites",
self.belongs_to.read().unwrap().urls.api
))
.json(&code),
limit_type: LimitType::Global,
}
.with_headers_for(self)
.send_and_deserialize_response::<Invite>(self)
.await
}
pub async fn create_channel_invite(
&mut self,
create_channel_invite_schema: CreateChannelInviteSchema,
channel_id: Snowflake,
) -> ChorusResult<GuildInvite> {
ChorusRequest {
request: Client::new()
.post(format!(
"{}/channels/{}/invites",
self.belongs_to.read().unwrap().urls.api,
channel_id
))
.json(&create_channel_invite_schema),
limit_type: LimitType::Channel(channel_id),
}
.with_headers_for(self)
.send_and_deserialize_response::<GuildInvite>(self)
.await
}
}