Skip to content

Commit

Permalink
change config reload to be before action, add autoflush
Browse files Browse the repository at this point in the history
  • Loading branch information
justinnamilee committed Feb 20, 2024
1 parent 14baae2 commit 8735e80
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
17 changes: 13 additions & 4 deletions fairu-chan
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


use strict;
use lib q[lib];
use lib q[lib]; # for linter


use fairu::config q[meta];
Expand All @@ -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]);
Expand All @@ -42,15 +46,20 @@ 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)
{
$idle = meta->{idleTime} || DEF_IDLE;

uwu($action);
}

$idle -= meta->{waitTime} || DEF_WAIT;
}

# bye felicia~
Expand Down
10 changes: 5 additions & 5 deletions lib/fairu/chan.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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(%+)
)
);
Expand All @@ -103,16 +103,14 @@ sub matchFiles($)
sub uwu($)
{
my ($error, $action) = (0, @_);

my $cache = getFiles();
my $map = matchFiles($cache);

foreach my $k (keys(%{$map}))
{
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);

Expand All @@ -137,6 +135,8 @@ sub uwu($)
$error++;
}
}

print qq[\u$mode: '$k' -> '$j'\n];
}

return ($error);
Expand Down
2 changes: 1 addition & 1 deletion lib/fairu/notification/discord.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ my $template = undef;
sub init($)
{
my ($error, $config) = (0, @_);

if (ref($config) eq q[HASH])
{
require Data::Validate::URI;
Expand Down

0 comments on commit 8735e80

Please sign in to comment.