diff --git a/src/lib.rs b/src/lib.rs index af357aa..b7fafad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,15 +26,10 @@ use std::sync::Arc; use std::sync::mpsc; use std::sync::mpsc::Sender; -use std::rc::Rc; -use std::cell::{Cell, RefCell}; - use transformable_channels::mpsc::TransformableSender; mod helpers; -use std::collections::btree_set::BTreeSet; - #[macro_use] extern crate log; @@ -105,16 +100,14 @@ impl Tenquestionmarks { let arc_envelope = Arc::new(envelope); for (key, sender) in &module_senders { let from_this = String::from(*key); - match self.subscriptions.get::(&from_this) { - Some(subscription) => { - if subscription.can_handle_event(&arc_envelope) { - match sender.send(arc_envelope.clone()) { - Err(err) => debug!("Failed to dispatch event to module \"{}\": {:?}", key, err), - Ok(_) => {} - } + if let Some(subscription) = self.subscriptions.get::(&from_this) { + if subscription.can_handle_event(&arc_envelope) { + if let Err(err) = sender.send(arc_envelope.clone()) { + debug!("Failed to dispatch event to module \"{}\": {:?}", key, err); } - }, - None => debug!("Failed to dispatch event to module \"{}\": No such module found!", key) + } + } else { + debug!("Failed to dispatch event to module \"{}\": No such module found!", key); } } }, diff --git a/src/main.rs b/src/main.rs index 6865425..d950bed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,35 +32,26 @@ fn main () { init_logger(); let config_file_name = env::args().nth(1).unwrap_or("tenquestionmarks.toml".into()); - match File::open(&config_file_name) { - Ok(mut file) => { - let mut contents = String::new(); - match file.read_to_string(&mut contents) { - Ok(_) => { - let mut parser = Parser::new(&contents); - match parser.parse() { - Some(configuration) => { - info!("Loaded configuration from: {}", config_file_name); - match Tenquestionmarks::from_configuration(configuration) { - Ok(tqm) => { - info!("tenquestionmarks initialized successfully"); - tqm.run(); - }, - Err(e) => error!("Failed to initialize tenquestionmarks: {:?}", e) - } - }, - None => { - error!("Failed to parse config file {}: {:?}. Config file must be a valid TOML file.", config_file_name, parser.errors); - } - } - }, - Err(e) => { - error!("Failed to open config file {}: {:?}", config_file_name, e); + if let Ok(mut file) = File::open(&config_file_name) { + let mut contents = String::new(); + if let Err(e) = file.read_to_string(&mut contents) { + error!("Failed to open config file {}: {:?}", config_file_name, e); + } else { + let mut parser = Parser::new(&contents); + if let Some(configuration) = parser.parse() { + info!("Loaded configuration from: {}", config_file_name); + match Tenquestionmarks::from_configuration(configuration) { + Ok(tqm) => { + info!("tenquestionmarks initialized successfully"); + tqm.run(); + }, + Err(e) => error!("Failed to initialize tenquestionmarks: {:?}", e) } + } else { + error!("Failed to parse config file {}: {:?}. Config file must be a valid TOML file.", config_file_name, parser.errors); } - }, - Err(_) => { - error!("Failed to open config file! Please specify path to a config file."); } + } else { + error!("Failed to open config file! Please specify path to a config file."); } } diff --git a/src/modules/discord.rs b/src/modules/discord.rs index 967d6c1..cfac717 100644 --- a/src/modules/discord.rs +++ b/src/modules/discord.rs @@ -147,9 +147,8 @@ impl EventLoop for DiscordModule { channel: discord.get_channel(message.channel_id).ok().and_then(|channel| make_channel_object(discord.clone(), channel)) }; - match sender.send(Envelope::new(event::Event::Message { message: message })) { - Err(err) => error!("Error sending message event: {:?}", err), - Ok(_) => {} + if let Err(err) = sender.send(Envelope::new(event::Event::Message { message: message })) { + error!("Error sending message event: {:?}", err) } } Ok(_) => {} diff --git a/tenquestionmarks.toml b/tenquestionmarks.toml index ad5c21c..f1e026c 100644 --- a/tenquestionmarks.toml +++ b/tenquestionmarks.toml @@ -85,4 +85,4 @@ end [autolink] [logger] -filters = [{ username = "Dave" }] +filters = [{ username = "Dave" }, { username = "Kevin" }]