Add guild delete route
This commit is contained in:
parent
d797a10009
commit
833c3733d7
|
@ -2,6 +2,7 @@ use serde_json::to_string;
|
||||||
|
|
||||||
use crate::api::schemas;
|
use crate::api::schemas;
|
||||||
use crate::api::types;
|
use crate::api::types;
|
||||||
|
use crate::errors::InstanceServerError;
|
||||||
|
|
||||||
impl<'a> types::Guild {
|
impl<'a> types::Guild {
|
||||||
/// Creates a new guild with the given parameters.
|
/// Creates a new guild with the given parameters.
|
||||||
|
@ -67,4 +68,59 @@ impl<'a> types::Guild {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Deletes a guild.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `user` - A mutable reference to a `User` instance.
|
||||||
|
/// * `instance` - A mutable reference to an `Instance` instance.
|
||||||
|
/// * `guild_id` - A `String` representing the ID of the guild to delete.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// An `Option` containing an `InstanceServerError` if an error occurred during the request, otherwise `None`.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// let mut user = User::new();
|
||||||
|
/// let mut instance = Instance::new();
|
||||||
|
/// let guild_id = String::from("1234567890");
|
||||||
|
///
|
||||||
|
/// match Guild::delete(&mut user, &mut instance, guild_id) {
|
||||||
|
/// Some(e) => println!("Error deleting guild: {:?}", e),
|
||||||
|
/// None => println!("Guild deleted successfully"),
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub async fn delete(
|
||||||
|
user: &mut types::User<'a>,
|
||||||
|
instance: &mut crate::instance::Instance,
|
||||||
|
guild_id: String,
|
||||||
|
) -> Option<InstanceServerError> {
|
||||||
|
let url = format!(
|
||||||
|
"{}/guilds/{}/delete/",
|
||||||
|
instance.urls.get_api().to_string(),
|
||||||
|
guild_id
|
||||||
|
);
|
||||||
|
let limits_user = user.limits.get_as_mut();
|
||||||
|
let limits_instance = instance.limits.get_as_mut();
|
||||||
|
let request = reqwest::Client::new()
|
||||||
|
.post(url.clone())
|
||||||
|
.bearer_auth(user.token.clone());
|
||||||
|
let mut requester = crate::limit::LimitedRequester::new().await;
|
||||||
|
let result = requester
|
||||||
|
.send_request(
|
||||||
|
request,
|
||||||
|
crate::api::limits::LimitType::Guild,
|
||||||
|
limits_instance,
|
||||||
|
limits_user,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
if result.is_err() {
|
||||||
|
Some(result.err().unwrap())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ custom_error! {
|
||||||
MultipartCreationError{error: String} = "Got an error whilst creating the form: {}",
|
MultipartCreationError{error: String} = "Got an error whilst creating the form: {}",
|
||||||
TokenExpired = "Token expired, invalid or not found.",
|
TokenExpired = "Token expired, invalid or not found.",
|
||||||
NoPermission = "You do not have the permissions needed to perform this action.",
|
NoPermission = "You do not have the permissions needed to perform this action.",
|
||||||
|
NotFound{error: String} = "The provided resource hasn't been found: {}",
|
||||||
}
|
}
|
||||||
|
|
||||||
custom_error! {
|
custom_error! {
|
||||||
|
|
Loading…
Reference in New Issue