mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Added $TELOXIDE_PROXY
to Bot::from_env
This commit is contained in:
parent
91001179ad
commit
bdbc226777
1 changed files with 18 additions and 6 deletions
|
@ -20,10 +20,20 @@ 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"),
|
||||
)
|
||||
match std::env::var_os("TELOXIDE_PROXY") {
|
||||
Some(proxy) => Self::from_env_with_client(
|
||||
Client::builder()
|
||||
.proxy(
|
||||
reqwest::Proxy::all(
|
||||
&proxy.to_string_lossy().to_string(),
|
||||
)
|
||||
.expect("creating reqwest::Proxy"),
|
||||
)
|
||||
.build()
|
||||
.expect("creating reqwest::Client"),
|
||||
),
|
||||
None => Self::from_env_with_client(Client::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new `Bot` with the `TELOXIDE_TOKEN` environmental variable (a
|
||||
|
@ -35,8 +45,10 @@ 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")
|
||||
.expect("Cannot get the TELOXIDE_TOKEN env variable"),
|
||||
&std::env::var_os("TELOXIDE_TOKEN")
|
||||
.expect("Cannot get the TELOXIDE_TOKEN env variable")
|
||||
.to_string_lossy()
|
||||
.to_string(),
|
||||
client,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue