From e62f1aa6120a07eaf8344b6c736f8028614e66af 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 | 50 +++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/http/client.rs b/src/http/client.rs index 8591f818690..b55fd1fe1b0 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -69,11 +69,13 @@ where /// ```rust /// # use serenity::http::HttpBuilder; /// # fn run() { -/// let http = HttpBuilder::new().proxy("http://127.0.0.1:3000").ratelimiter_disabled(true).build(); +/// let http = HttpBuilder::without_token() +/// .proxy("http://127.0.0.1:3000") +/// .ratelimiter_disabled(true) +/// .build(); /// # } /// ``` #[must_use] -#[derive(Default)] pub struct HttpBuilder { client: Option, ratelimiter: Option, @@ -86,8 +88,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 +122,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 +247,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 {