From e2d0e52e2b498d7fb760afb2aa2ca7735e0b8220 Mon Sep 17 00:00:00 2001 From: justinnamilee Date: Tue, 30 Apr 2024 17:47:53 -0300 Subject: [PATCH] rename notif types, and clean up --- lib/fairu/chan.pm | 4 ++-- lib/fairu/config.pm | 2 +- lib/fairu/notification.pm | 21 +++++++++++++-------- sample-conf.yml | 6 +++--- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/fairu/chan.pm b/lib/fairu/chan.pm index e92d397..a538c24 100644 --- a/lib/fairu/chan.pm +++ b/lib/fairu/chan.pm @@ -143,7 +143,7 @@ sub uwu($) { if (($mode eq q[move] && move($ifile, $ofile)) || ($mode eq q[copy] && copy($ifile, $ofile))) { - fairu::notification::action($f); + fairu::notification::send(q[action], $f); $count++ } else @@ -157,7 +157,7 @@ sub uwu($) } } - fairu::notification::internal(sprintf(q[Matched %d files, processed %d files!], int(keys(%{$map})), $count)) if $count > 0; + fairu::notification::send(q[information], sprintf(q[Matched %d files, processed %d files!], int(keys(%{$map})), $count)) if $count > 0; return ($error); } diff --git a/lib/fairu/config.pm b/lib/fairu/config.pm index 1e86a51..f6bec89 100644 --- a/lib/fairu/config.pm +++ b/lib/fairu/config.pm @@ -247,7 +247,7 @@ sub parse($) $config = $newConfig; print qq[Config loaded...\n]; - fairu::notification::internal(q[Config loaded...]); + fairu::notification::send(q[information], q[Config loaded...]); } elsif (defined($config)) { diff --git a/lib/fairu/notification.pm b/lib/fairu/notification.pm index 6500319..390b241 100644 --- a/lib/fairu/notification.pm +++ b/lib/fairu/notification.pm @@ -11,7 +11,10 @@ use fairu::notification::discord; # TODO: more notification types here? -my $notification = {internal => [], action => []}; +sub TYPE() { qw[event information debug] } + + +my $notification = { map { $_ => [] } TYPE }; sub init($) @@ -26,8 +29,10 @@ sub init($) { if (ref(my $n = fairu::notification::discord->new($config->{$k}))) { - push(@{$notification->{internal}}, $n) if lc($config->{$k}->{for}) eq q[internal] || !exists($config->{$k}->{for}); - push(@{$notification->{action}}, $n) if lc($config->{$k}->{for}) eq q[action] || !exists($config->{$k}->{for}); + foreach my $t (TYPE) + { + push(@{$notification->{$t}}, $n) if lc($config->{$k}->{for}) eq $t || !exists($config->{$k}->{for}); + } } else { @@ -47,7 +52,7 @@ sub init($) return ($error); } -sub notify($@) +sub send($@) { my ($mode, @data) = @_; @@ -57,11 +62,11 @@ sub notify($@) eval { $_->handler(@data) for @{$notification->{$mode}} }; warn qq[Ran into notification sending issues.\n] if ($@); } + else + { + warn qq[Unknown notification type '$mode'.\n]; + } } -sub debug(@) { notify(q[debug], @_) } -sub action(@) { notify(q[action], @_) } -sub internal(@) { notify(q[internal], @_) } - __PACKAGE__ diff --git a/sample-conf.yml b/sample-conf.yml index d21c40d..27405b5 100644 --- a/sample-conf.yml +++ b/sample-conf.yml @@ -24,14 +24,14 @@ meta: type: discord webhookUrl: https://discord.com/api/webhooks/69696969/lkjasdlkjasdlkjasdlkjasdlkjasd template: "Posted `%s` to Plex! Go enjoy, you filthy weeb. :hot_face: :hot_face:" - # (OPTIONAL) which messages does this apply? default to ALL; options here are "internal" or "action" - for: action + # (OPTIONAL) which messages does this apply? default to ALL; options here are "event", "information", or "debug" + for: event # this one will be used for internal cause it has the "for: internal" tag discord_internal: type: discord webhookUrl: https://discord.com/api/webhooks/420420420/jkshraqkudaihfjkseafhaksjhd template: ":crocodile: Fairu-chan says, '%s.'" - for: internal + for: information # (REQUIRED) here you'll have your groups data: