From 768fe8398d8c21553eae6b76a1cfcb216a51d114 Mon Sep 17 00:00:00 2001 From: n3tw0rth Date: Wed, 12 Feb 2025 17:30:34 +0530 Subject: [PATCH] feat(triggers): add trigger name to the trigger notification --- src/main.rs | 22 +++++++++++----------- src/notification.rs | 7 +++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index ae3ab42..7b092f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,12 +56,11 @@ struct EmailConfig { #[tokio::main] async fn main() -> anyhow::Result<()> { + // Parse the command line arguments let mut args = Args::parse(); let config = helpers::app_state().await?; - // helpers::handle_ctrlc().await; - let program = args.run.get(0).cloned().unwrap(); let program_args = args.run.split_off(1); @@ -84,23 +83,24 @@ async fn main() -> anyhow::Result<()> { if args.triggers.is_some() { // Check if the line contains a trigger string - let contains_a_trigger = args + let contained_triggers: Vec<_> = args .triggers .as_ref() .unwrap() .split(",") - .collect::>() - .iter() - .any(|t| line.contains(t)); - if contains_a_trigger { - let _ = notification::Notification::new( + .filter(|trigger| line.contains(trigger)) + .collect(); + + if contained_triggers.len() > 0 { + notification::Notification::new( &config, &args.profiles.as_ref().unwrap(), "Trigger Detected".to_string(), - "".to_string(), + contained_triggers.join(","), ) - .send() - .await; + .send_trigger() + .await + .unwrap(); } } } diff --git a/src/notification.rs b/src/notification.rs index d57f54a..d397b98 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -115,4 +115,11 @@ impl<'b> Notification<'b> { Ok(()) } + + pub async fn send_trigger(&mut self) -> anyhow::Result<()> { + // expect a list of triggers found and will update the notification massage based on that + self.msg = format!("Triggers invoked {}", self.msg); + self.send().await?; + Ok(()) + } }