Add BotBuilder

This commit is contained in:
Temirkhan Myrzamadi 2020-07-16 18:52:39 +06:00
parent 0c965473a2
commit f2bc67617d

View file

@ -72,3 +72,34 @@ impl Bot {
&self.client &self.client
} }
} }
#[derive(Debug)]
struct BotBuilder {
token: Option<String>,
client: Option<Client>,
}
impl BotBuilder {
#[must_use]
pub fn new() -> Self {
Self { token: None, client: None }
}
#[must_use]
pub fn client(mut self, client: Client) -> Self {
self.client = Some(client);
self
}
#[must_use]
pub fn token(mut self, token: S) -> Self where S: Into<String> {
self.token = Some(token.into());
self
}
#[must_use]
pub fn build(self) -> Bot {
Bot { client: self.client.unwrap_or(Client::new()), token: self.token.unwrap_or(std::env::var("TELOXIDE_TOKEN")
.expect("Cannot get the TELOXIDE_TOKEN env variable"))}
}
}