From 1fb3ef6766552a8cd8b26505adc18e05e66560a7 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 28 May 2023 23:04:35 +0200 Subject: [PATCH] Create channels() for Guild This method retrieves all channels from a guild --- src/api/guilds/guilds.rs | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/api/guilds/guilds.rs b/src/api/guilds/guilds.rs index d1f03f0..6a5092f 100644 --- a/src/api/guilds/guilds.rs +++ b/src/api/guilds/guilds.rs @@ -148,6 +148,60 @@ impl Guild { ) .await } + + /// Returns a `Result` containing a vector of `Channel` structs if the request was successful, or an `InstanceServerError` if there was an error. + /// + /// # Arguments + /// + /// * `url_api` - A string slice that holds the URL of the API. + /// * `token` - A string slice that holds the authorization token. + /// * `limits_user` - A mutable reference to a `Limits` struct containing the user's rate limits. + /// * `limits_instance` - A mutable reference to a `Limits` struct containing the instance's rate limits. + /// + pub async fn channels( + &self, + url_api: &str, + token: &str, + limits_user: &mut Limits, + limits_instance: &mut Limits, + ) -> Result, InstanceServerError> { + let request = Client::new() + .get(format!( + "{}/guilds/{}/channels/", + url_api, + self.id.to_string() + )) + .bearer_auth(token); + let result = match LimitedRequester::new() + .await + .send_request( + request, + crate::api::limits::LimitType::Guild, + limits_instance, + limits_user, + ) + .await + { + Ok(result) => result, + Err(e) => return Err(e), + }; + let stringed_response = match result.text().await { + Ok(value) => value, + Err(e) => { + return Err(InstanceServerError::InvalidResponseError { + error: e.to_string(), + }) + } + }; + let _: Vec = match from_str(&stringed_response) { + Ok(result) => return Ok(result), + Err(e) => { + return Err(InstanceServerError::InvalidResponseError { + error: e.to_string(), + }) + } + }; + } } impl Channel {