diff --git a/Cargo.toml b/Cargo.toml index bc8a493..9d19031 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ transformable_channels = "0.1.1" time = "0.1" regex = "0.2" multimap = "0.4.0" +notify = "4.0.0" pvn = { git = "http://gitlab.monarch-pass.net/malacoda/pvn.git" } echobox = { git = "http://gitlab.monarch-pass.net/malacoda/echobox.git" } stc = { git = "http://gitlab.monarch-pass.net/malacoda/stc.git" } diff --git a/src/main.rs b/src/main.rs index 18e40ae..e178d67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,9 @@ use std::env; use std::fs::File; use std::io::{Read, Write}; +use std::sync::mpsc; +use std::time::Duration; + extern crate tenquestionmarks; use tenquestionmarks::Tenquestionmarks; @@ -14,6 +17,8 @@ extern crate env_logger; extern crate time; extern crate crossbeam; +extern crate notify; +use notify::{RecommendedWatcher, Watcher, RecursiveMode, DebouncedEvent}; fn init_logger () { let mut builder = env_logger::Builder::new(); @@ -37,9 +42,20 @@ fn main () { Ok(tqm) => { info!("tenquestionmarks initialized successfully"); crossbeam::scope(|scope| { - //scope.spawn(|| { - // tqm.reconfigure(&read_config_from_file(&config_file_name)); - //}); + scope.spawn(|| { + let (notify_sender, notify_reciever) = mpsc::channel(); + let mut watcher: RecommendedWatcher = Watcher::new(notify_sender, Duration::from_secs(2)).expect("Failed to create watcher"); + watcher.watch(&config_file_name, RecursiveMode::NonRecursive).expect("Failed to watch config file"); + + loop { + if let Ok(event) = notify_reciever.recv() { + if let DebouncedEvent::Write(_) = event { + info!("Detected modified config file, reconfiguring"); + tqm.reconfigure(&read_config_from_file(&config_file_name)); + } + } + } + }); tqm.run(); }) diff --git a/tenquestionmarks.toml b/tenquestionmarks.toml index 5811e1a..6489b25 100644 --- a/tenquestionmarks.toml +++ b/tenquestionmarks.toml @@ -107,4 +107,4 @@ responses = ["Did some carbon-based lifeform just say **I C E**?"] type = "random" parents = ["stdin", "discord"] pattern = "^?slap (.*)" -responses = ["/me slaps $1 around a bit with a large trout"] +responses = ["/me slaps $1 around a bit with a large trout", "/me slaps $1 around a bit with a large brick"]