From f2bc67617db9e2d887b9fff8350e48928761bfa7 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 16 Jul 2020 18:52:39 +0600 Subject: [PATCH] Add BotBuilder --- src/bot/mod.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/bot/mod.rs b/src/bot/mod.rs index 433a6cab..3b53b1f2 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -72,3 +72,34 @@ impl Bot { &self.client } } + +#[derive(Debug)] +struct BotBuilder { + token: Option, + client: Option, +} + +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 { + 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"))} + } +}