Merge branch 'refactor-guess-a-number-bot' of https://github.com/teloxide/teloxide into refactor-guess-a-number-bot

This commit is contained in:
Temirkhan Myrzamadi 2020-03-09 14:59:59 +06:00
commit e44a2204bf
3 changed files with 14 additions and 5 deletions

View file

@ -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,
)

View 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(),
}
}

View file

@ -1,5 +1,6 @@
//! Some useful utilities.
pub mod client_from_env;
pub mod command;
pub mod html;
pub mod markdown;