From 8277ca41cb8a005d51baa5bd82cba27c9d2e0ab1 Mon Sep 17 00:00:00 2001 From: Michael Krasnitski Date: Wed, 20 Nov 2024 11:56:08 -0500 Subject: [PATCH] Fix HttpBuilder constructors --- src/http/client.rs | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/http/client.rs b/src/http/client.rs index 8591f818690..1dfac648870 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -73,7 +73,6 @@ where /// # } /// ``` #[must_use] -#[derive(Default)] pub struct HttpBuilder { client: Option, ratelimiter: Option, @@ -86,8 +85,32 @@ pub struct HttpBuilder { impl HttpBuilder { /// Construct a new builder. - pub fn new() -> Self { - Self::default() + pub fn new(token: Token) -> Self { + Self { + client: None, + ratelimiter: None, + ratelimiter_disabled: false, + token: Some(token), + proxy: None, + application_id: None, + default_allowed_mentions: None, + } + } + + /// Construct a new builder without a token set. + /// + /// Most Discord functionality requires a logged-in Bot token, but there are some exceptions + /// such as webhook endpoints. + pub fn without_token() -> Self { + Self { + client: None, + ratelimiter: None, + ratelimiter_disabled: false, + token: None, + proxy: None, + application_id: None, + default_allowed_mentions: None, + } } /// Sets the application_id to use interactions. @@ -96,12 +119,6 @@ impl HttpBuilder { self } - /// Sets an authorization token for the bot. - pub fn token(mut self, token: Token) -> Self { - self.token = Some(token); - self - } - /// Sets the [`reqwest::Client`]. If one isn't provided, a default one will be used. pub fn client(mut self, client: Client) -> Self { self.client = Some(client); @@ -227,14 +244,16 @@ impl Http { /// Construct an authorized HTTP client. #[must_use] pub fn new(token: Token) -> Self { - HttpBuilder::new().token(token).build() + HttpBuilder::new(token).build() } - /// Construct an unauthorized HTTP client, with no token. Few things will work, but webhooks - /// are one exception. + /// Construct an unauthorized HTTP client, with no token. + /// + /// Most Discord functionality requires a logged-in Bot token, but there are some exceptions + /// such as webhook endpoints. #[must_use] pub fn without_token() -> Self { - HttpBuilder::new().build() + HttpBuilder::without_token().build() } pub fn application_id(&self) -> Option {