Skip to content

Commit

Permalink
rename notif types, and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
justinnamilee committed Apr 30, 2024
1 parent 8f0d47a commit e2d0e52
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/fairu/chan.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/fairu/config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
21 changes: 13 additions & 8 deletions lib/fairu/notification.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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($)
Expand All @@ -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
{
Expand All @@ -47,7 +52,7 @@ sub init($)
return ($error);
}

sub notify($@)
sub send($@)
{
my ($mode, @data) = @_;

Expand All @@ -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__
6 changes: 3 additions & 3 deletions sample-conf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e2d0e52

Please sign in to comment.