Update config constructor functions

This commit is contained in:
Joscha 2023-01-21 16:22:54 +01:00
parent fb8bb33965
commit d02b9a2e76
2 changed files with 13 additions and 9 deletions

View file

@ -153,6 +153,10 @@ async fn on_event(event: Event) -> Result<(), ()> {
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let _instance = Config::new("test").username("TestBot").build(on_event); let _instance = Config::new("test")
.username(Some("TestBot"))
.build(on_event);
// Once the instance is dropped, it stops, so we wait indefinitely here.
tokio::time::sleep(Duration::from_secs(u64::MAX)).await; tokio::time::sleep(Duration::from_secs(u64::MAX)).await;
} }

View file

@ -63,23 +63,23 @@ impl Config {
self self
} }
pub fn human(mut self) -> Self { pub fn human(mut self, human: bool) -> Self {
self.human = true; self.human = human;
self self
} }
pub fn bot(mut self) -> Self { pub fn cookies(mut self, cookies: Arc<Mutex<CookieJar>>) -> Self {
self.human = false; self.cookies = cookies;
self self
} }
pub fn username<S: ToString>(mut self, username: S) -> Self { pub fn username<S: ToString>(mut self, username: Option<S>) -> Self {
self.username = Some(username.to_string()); self.username = username.map(|s| s.to_string());
self self
} }
pub fn password<S: ToString>(mut self, password: S) -> Self { pub fn password<S: ToString>(mut self, password: Option<S>) -> Self {
self.password = Some(password.to_string()); self.password = password.map(|s| s.to_string());
self self
} }