diff options
| -rw-r--r-- | src/api/guzzle.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/api/guzzle.rs b/src/api/guzzle.rs index 0321127..b58f323 100644 --- a/src/api/guzzle.rs +++ b/src/api/guzzle.rs @@ -1,3 +1,4 @@ +use once_cell::sync::Lazy; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; @@ -8,11 +9,22 @@ struct GuzzleResponse { const GUZZLE: &str = "https://api.mydadleft.me"; +pub static REQWEST_CLIENT: Lazy<reqwest::Client> = Lazy::new(|| { + reqwest::Client::builder() + .user_agent("teawieBot/0.1.0") + .build() + .unwrap_or_default() +}); + pub async fn get_random_teawie() -> String { let endpoint = "get_random_teawie"; - let resp = reqwest::get(format!("{GUZZLE}/{endpoint}")).await.unwrap(); // why did i have to own - // this constant? i have - // no idea! + let req = REQWEST_CLIENT + .get(format!("{GUZZLE}/{endpoint}")) + .build() + .unwrap(); + let resp = REQWEST_CLIENT.execute(req).await.unwrap(); // why did i have to own + // this constant? i have + // no idea! let err_msg = "couldn't get a teawie"; match resp.status() { |
