mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-23 06:51:01 +01:00
Add BotBuilder
This commit is contained in:
parent
0c965473a2
commit
f2bc67617d
1 changed files with 31 additions and 0 deletions
|
@ -72,3 +72,34 @@ impl Bot {
|
|||
&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"))}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue