Skip to content

Commit

Permalink
Merge pull request #10 from n3tw0rth/feat/trigger-msg
Browse files Browse the repository at this point in the history
feat(triggers): add trigger name to the trigger notification
  • Loading branch information
n3tw0rth authored Feb 12, 2025
2 parents 2bbcd7c + 768fe83 commit fa04fb3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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::<Vec<_>>()
.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();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}

0 comments on commit fa04fb3

Please sign in to comment.