From 8735e80a60e62a729b6a876272087c2cbace331e Mon Sep 17 00:00:00 2001 From: justinnamilee Date: Mon, 19 Feb 2024 22:49:35 -0400 Subject: [PATCH] change config reload to be before action, add autoflush --- fairu-chan | 17 +++++++++++++---- lib/fairu/chan.pm | 10 +++++----- lib/fairu/notification/discord.pm | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/fairu-chan b/fairu-chan index ef7833e..9a73f61 100755 --- a/fairu-chan +++ b/fairu-chan @@ -2,7 +2,7 @@ use strict; -use lib q[lib]; +use lib q[lib]; # for linter use fairu::config q[meta]; @@ -21,11 +21,15 @@ my $action = 0; my $file = $ARGV[IDX_FILE]; my $run = 0; my $idle = 0; +my $reload = 0; + +# setup autoflush +our $| = 1; # signal handlers $SIG{TERM} = sub { $run = 0 }; $SIG{USR1} = sub { $idle = 0 }; -$SIG{USR2} = sub { fairu::config::parse($file) }; +$SIG{USR2} = sub { $reload = 1 }; # set the run mode $action = 1, $run = 0 if (lc($ARGV[IDX_MODE]) eq q[run]); @@ -42,6 +46,13 @@ uwu($action); #* the best part of programming is naming your own functions while ($run) { sleep(meta->{waitTime} || DEF_WAIT); + $idle -= meta->{waitTime} || DEF_WAIT; + + if ($run && $reload) + { + $reload = 0; + fairu::config::parse($file); + } if ($run && $idle <= 0) { @@ -49,8 +60,6 @@ while ($run) uwu($action); } - - $idle -= meta->{waitTime} || DEF_WAIT; } # bye felicia~ diff --git a/lib/fairu/chan.pm b/lib/fairu/chan.pm index c9597a9..c6a1354 100644 --- a/lib/fairu/chan.pm +++ b/lib/fairu/chan.pm @@ -83,11 +83,11 @@ sub matchFiles($) #? apply a "local" mapping function if it exists ? $group->{mapFunction}->{$_}->($+{$_}) - + #? if not, try a "global" mapping function, otherwise return the raw data : (exists(meta->{mapFunction}->{$_}) ? meta->{mapFunction}->{$_}->($+{$_}) : $+{$_}) - #? from the %+ we take data in lexical order (https://perldoc.perl.org/functions/sort) + #? from the %+ we take data in lexical order (https://perldoc.perl.org/functions/sort) } sort keys(%+) ) ); @@ -103,7 +103,7 @@ sub matchFiles($) sub uwu($) { my ($error, $action) = (0, @_); - + my $cache = getFiles(); my $map = matchFiles($cache); @@ -111,8 +111,6 @@ sub uwu($) { my ($mode, $j) = ($map->{$k}->{mode}, $map->{$k}->{file}); - print qq['$k' -> '$j'\n]; - my ($v, $d, $f) = File::Spec->splitpath($j); my $path = File::Spec->join($v, $d); @@ -137,6 +135,8 @@ sub uwu($) $error++; } } + + print qq[\u$mode: '$k' -> '$j'\n]; } return ($error); diff --git a/lib/fairu/notification/discord.pm b/lib/fairu/notification/discord.pm index 44d0360..ea274cb 100644 --- a/lib/fairu/notification/discord.pm +++ b/lib/fairu/notification/discord.pm @@ -14,7 +14,7 @@ my $template = undef; sub init($) { my ($error, $config) = (0, @_); - + if (ref($config) eq q[HASH]) { require Data::Validate::URI;