From 32e870aeefee587d6eabdfa08cf27b3cf9a46f15 Mon Sep 17 00:00:00 2001 From: Jokler Date: Sun, 24 Dec 2017 15:27:14 +0100 Subject: Exit if no bot connected successfully --- bin/main.rs | 9 ++++++--- src/lib.rs | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bin/main.rs b/bin/main.rs index 420e016..c9749b6 100644 --- a/bin/main.rs +++ b/bin/main.rs @@ -78,6 +78,7 @@ fn main() { // Create an event loop to run the connections on. let mut reactor = Core::new().unwrap(); + let mut task = false; // Open a connection and add work for each config for config in configs { @@ -104,9 +105,11 @@ fn main() { } } - bot.connect(&mut reactor, &config); + bot.connect(&mut reactor, &config).map(|_| task = true); } - // Run the main loop forever - reactor.run(future::empty::<(), ()>()).unwrap(); + if task { + // Run the main loop forever + reactor.run(future::empty::<(), ()>()).unwrap(); + } } diff --git a/src/lib.rs b/src/lib.rs index 5d15802..5592da7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -132,7 +132,7 @@ impl Bot { /// reactor.run(future::empty::<(), ()>()).unwrap(); /// # } /// ``` - pub fn connect(&self, reactor: &mut Core, config: &Config) { + pub fn connect(&self, reactor: &mut Core, config: &Config) -> Option<()> { info!("Plugins loaded: {}", self.plugins); let server = @@ -140,7 +140,7 @@ impl Bot { Ok(v) => v, Err(e) => { error!("Failed to connect: {}", e); - return; + return None; } }; @@ -148,7 +148,10 @@ impl Bot { match server.identify() { Ok(_) => info!("Identified"), - Err(e) => error!("Failed to identify: {}", e), + Err(e) => { + error!("Failed to identify: {}", e); + return None; + } }; // TODO Verify if we actually need to clone plugins twice @@ -160,6 +163,7 @@ impl Bot { .map_err(|e| error!("Failed to process message: {}", e)); reactor.handle().spawn(task); + Some(()) } } -- cgit v1.2.3-70-g09d2