mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-23 15:01:45 +01:00
Merge branch 'refactor-guess-a-number-bot' of https://github.com/teloxide/teloxide into refactor-guess-a-number-bot
This commit is contained in:
commit
e44a2204bf
3 changed files with 14 additions and 5 deletions
|
@ -20,10 +20,7 @@ impl Bot {
|
|||
///
|
||||
/// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html
|
||||
pub fn from_env() -> Arc<Self> {
|
||||
Self::new(
|
||||
std::env::var("TELOXIDE_TOKEN")
|
||||
.expect("Cannot get the TELOXIDE_TOKEN env variable"),
|
||||
)
|
||||
Self::from_env_with_client(Client::new())
|
||||
}
|
||||
|
||||
/// Creates a new `Bot` with the `TELOXIDE_TOKEN` environmental variable (a
|
||||
|
@ -35,7 +32,7 @@ impl Bot {
|
|||
/// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html
|
||||
pub fn from_env_with_client(client: Client) -> Arc<Self> {
|
||||
Self::with_client(
|
||||
std::env::var("TELOXIDE_TOKEN")
|
||||
&std::env::var("TELOXIDE_TOKEN")
|
||||
.expect("Cannot get the TELOXIDE_TOKEN env variable"),
|
||||
client,
|
||||
)
|
||||
|
|
11
src/utils/client_from_env.rs
Normal file
11
src/utils/client_from_env.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
pub fn client_from_env() -> reqwest::Client {
|
||||
use reqwest::{Client, Proxy};
|
||||
|
||||
match std::env::var("TELOXIDE_PROXY").ok() {
|
||||
Some(proxy) => Client::builder()
|
||||
.proxy(Proxy::all(&proxy).expect("creating reqwest::Proxy"))
|
||||
.build()
|
||||
.expect("creating reqwest::Client"),
|
||||
None => Client::new(),
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
//! Some useful utilities.
|
||||
|
||||
pub mod client_from_env;
|
||||
pub mod command;
|
||||
pub mod html;
|
||||
pub mod markdown;
|
||||
|
|
Loading…
Reference in a new issue