diff --git a/bin/aleesa-jabber-bot b/bin/aleesa-jabber-bot index 0dda053..11005e5 100755 --- a/bin/aleesa-jabber-bot +++ b/bin/aleesa-jabber-bot @@ -13,13 +13,13 @@ my $workdir; # before we run, change working dir BEGIN { use Cwd qw (chdir abs_path); - my @CWD = split (/\//, abs_path ($PROGRAM_NAME)); + my @CWD = split /\//, abs_path ($PROGRAM_NAME); if ($#CWD > 1) { $#CWD = $#CWD - 2; } - $workdir = join ('/', @CWD); + $workdir = join '/', @CWD; chdir $workdir; } @@ -87,8 +87,10 @@ if ($UID == 0) { } if (defined $logfile) { - Log::Any::Adapter->set ('File', $logfile, 'log_level'=>'warning'); # fatal + # loglevel warning suppresses logging from CHI. + Log::Any::Adapter->set ('File', $logfile, 'log_level'=>'warning'); } else { + # no log defined so set loglevel to the least verbose Log::Any::Adapter->set ('File', '/dev/null', 'log_level'=>'emergency'); } diff --git a/confcheck.pl b/confcheck.pl index c2adc42..0b18981 100755 --- a/confcheck.pl +++ b/confcheck.pl @@ -12,7 +12,7 @@ use JSON::PP; use version; our $VERSION = qw (1.0); my $c = 'data/config.json'; -open (my $C, '<', $c) || die "No conf at $c: $OS_ERROR\n"; ## no critic (InputOutput::RequireBriefOpen) +open (my $C, '<', $c) || die "No conf at $c: $OS_ERROR\n"; my $len = (stat $c) [7]; my $json; my $readlen = read ($C, $json, $len); diff --git a/lib/BotLib/Buni.pm b/lib/BotLib/Buni.pm index ce1b345..0fee379 100644 --- a/lib/BotLib/Buni.pm +++ b/lib/BotLib/Buni.pm @@ -37,7 +37,7 @@ sub Buni { { do { $#a = -1; - @a = $p->get_tag('meta'); ## no critic (Variables::RequireLocalizedPunctuationVars) + @a = $p->get_tag ('meta'); ## no critic (Variables::RequireLocalizedPunctuationVars) if (defined $a[0][1]->{property} && $a[0][1]->{property} eq 'og:image') { $ret = $a[0][1]->{content}; diff --git a/lib/BotLib/Conf.pm b/lib/BotLib/Conf.pm index c2aeb26..9193cb4 100644 --- a/lib/BotLib/Conf.pm +++ b/lib/BotLib/Conf.pm @@ -5,13 +5,13 @@ use 5.018; use strict; use warnings; use utf8; -use open qw(:std :utf8); -use English qw( -no_match_vars ); +use open qw (:std :utf8); +use English qw ( -no_match_vars ); use JSON::XS; use version; our $VERSION = qw (1.0); -use Exporter qw(import); -our @EXPORT_OK = qw(LoadConf); +use Exporter qw (import); +our @EXPORT_OK = qw (LoadConf); sub LoadConf { my $c = 'data/config.json'; diff --git a/lib/BotLib/Drink.pm b/lib/BotLib/Drink.pm index d8c5110..9254989 100644 --- a/lib/BotLib/Drink.pm +++ b/lib/BotLib/Drink.pm @@ -43,27 +43,27 @@ sub Drink { if ($r->{success}) { # TODO: Handle unexpected content - my $p = HTML::TokeParser->new(\$r->{content}); + my $p = HTML::TokeParser->new (\$r->{content}); my @a; - my @holyday; + my @holiday; do { $#a = -1; - @a = $p->get_tag('span'); ## no critic (Variables::RequireLocalizedPunctuationVars) + @a = $p->get_tag ('span'); ## no critic (Variables::RequireLocalizedPunctuationVars) if ($#{$a[0]} > 2 && defined $a[0][1]->{itemprop} && $a[0][1]->{itemprop} eq 'text') { - push @holyday,'* ' . decode ('UTF-8', $p->get_trimmed_text ('/span')); + push @holiday,'* ' . decode ('UTF-8', $p->get_trimmed_text ('/span')); } } while ($#{$a[0]} > 1); - if ($#holyday > 0) { + if ($#holiday > 0) { # cut off something weird, definely not a "holyday" - $#holyday = $#holyday - 1; + $#holiday = $#holiday - 1; } - if ($#holyday > 0) { - $ret = join "\n", @holyday; + if ($#holiday > 0) { + $ret = join "\n", @holiday; } } else { cluck sprintf 'Server return status %s with message: %s', $r->{status}, $r->{reason}; diff --git a/lib/BotLib/Fox.pm b/lib/BotLib/Fox.pm index f89bf4b..c4b980d 100644 --- a/lib/BotLib/Fox.pm +++ b/lib/BotLib/Fox.pm @@ -10,10 +10,9 @@ use Carp qw (carp); use JSON::XS; use HTTP::Tiny; -use vars qw/$VERSION/; +use version; our $VERSION = qw (1.0); use Exporter qw (import); our @EXPORT_OK = qw (Fox); -$VERSION = '1.0'; sub Fox { my $r; diff --git a/lib/BotLib/Image/Flickr.pm b/lib/BotLib/Image/Flickr.pm index 431c31c..d33678e 100644 --- a/lib/BotLib/Image/Flickr.pm +++ b/lib/BotLib/Image/Flickr.pm @@ -43,7 +43,7 @@ sub mknonce { return $nonce; } -sub flickerSignReq { +sub flickrSignReq { my %p = @_; my $string; my $hmac; @@ -105,7 +105,7 @@ sub flickrRequestToken { my $oauth_timestamp = time (); my $oauth_nonce = mknonce (); - my $oauth_signature = flickerSignReq ( + my $oauth_signature = flickrSignReq ( type => 'request_token', oauth_timestamp => $oauth_timestamp, oauth_nonce => $oauth_nonce @@ -142,7 +142,7 @@ sub flickrAccessToken { my $oauth_timestamp = time (); my $oauth_nonce = mknonce (); - my $oauth_signature = flickerSignReq ( + my $oauth_signature = flickrSignReq ( type => 'access_token', oauth_timestamp => $oauth_timestamp, oauth_nonce => $oauth_nonce, @@ -201,7 +201,7 @@ sub flickrTestLogin { my $oauth_timestamp = time (); my $oauth_nonce = mknonce (); - my $oauth_signature = flickerSignReq ( + my $oauth_signature = flickrSignReq ( nojsoncallback => 1, oauth_nonce => $oauth_nonce, format => 'json', @@ -254,7 +254,7 @@ sub flickrSearchByText { my $oauth_timestamp = time (); my $oauth_nonce = mknonce (); - my $oauth_signature = flickerSignReq ( + my $oauth_signature = flickrSignReq ( nojsoncallback => 1, oauth_nonce => $oauth_nonce, format => 'json', @@ -293,10 +293,10 @@ sub flickrSearchByText { if (defined $response) { # lets make another query, this time with random picture - my $page = irand int ($response->{photos}->{total} / 500); + my $page = irand (int $response->{photos}->{total} / 500); $oauth_timestamp = time (); $oauth_nonce = mknonce (); - $oauth_signature = flickerSignReq ( + $oauth_signature = flickrSignReq ( nojsoncallback => 1, oauth_nonce => $oauth_nonce, format => 'json', @@ -363,7 +363,7 @@ sub flickrSearchByTags { my $oauth_timestamp = time (); my $oauth_nonce = mknonce (); - my $oauth_signature = flickerSignReq ( + my $oauth_signature = flickrSignReq ( nojsoncallback => 1, oauth_nonce => $oauth_nonce, format => 'json', @@ -405,7 +405,7 @@ sub flickrSearchByTags { my $page = irand int ($response->{photos}->{total} / 500); $oauth_timestamp = time (); $oauth_nonce = mknonce (); - $oauth_signature = flickerSignReq ( + $oauth_signature = flickrSignReq ( nojsoncallback => 1, oauth_nonce => $oauth_nonce, format => 'json', @@ -582,7 +582,7 @@ sub FlickrByTags { if ($result) { if (defined ($result->{photos}) && defined ($result->{photos}->{photo})) { - my $item = irand int(@{$result->{photos}->{photo}}); + my $item = irand int @{$result->{photos}->{photo}}; $item = ${$result->{photos}->{photo}}[$item]; $item = sprintf 'https://live.staticflickr.com/%s/%s_%s_z.jpg', $item->{server}, $item->{id}, $item->{secret}; return $item; @@ -623,7 +623,7 @@ sub FlickrByText { if ($result) { if (defined ($result->{photos}) && defined ($result->{photos}->{photo})) { - my $item = irand int(@{$result->{photos}->{photo}}); + my $item = irand (int (@{$result->{photos}->{photo}})); $item = ${$result->{photos}->{photo}}[$item]; $item = sprintf 'https://live.staticflickr.com/%s/%s_%s_z.jpg', $item->{server}, $item->{id}, $item->{secret}; return $item; diff --git a/lib/BotLib/Kitty.pm b/lib/BotLib/Kitty.pm index 90c1873..a27d384 100644 --- a/lib/BotLib/Kitty.pm +++ b/lib/BotLib/Kitty.pm @@ -34,7 +34,7 @@ sub Kitty { decode_json ($r->{content}) }; - if ($EVAL_ERROR) { + unless (defined $jcat) { carp "[ERROR] Unable to decode JSON: $EVAL_ERROR"; } else { if ($jcat->[0]->{url}) { diff --git a/lib/BotLib/Monkeyuser.pm b/lib/BotLib/Monkeyuser.pm index ab1c6ec..ab64408 100644 --- a/lib/BotLib/Monkeyuser.pm +++ b/lib/BotLib/Monkeyuser.pm @@ -37,7 +37,7 @@ sub Monkeyuser { do { $#a = -1; - @a = $p->get_tag('a'); ## no critic (Variables::RequireLocalizedPunctuationVars) + @a = $p->get_tag ('a'); ## no critic (Variables::RequireLocalizedPunctuationVars) if (defined $a[0][1]->{class} && $a[0][1]->{class} eq 'lazyload small-image') { if (defined $a[0][1]->{'data-src'} && ($a[0][1]->{'data-src'} !~ /adlitteram/)) { @@ -48,7 +48,7 @@ sub Monkeyuser { } while ($#{$a[0]} > 1); if ($#link > 0) { - $ret = sprintf 'https://www.monkeyuser.com%s', $link [irand (1 + $#link)]; + $ret = sprintf 'https://www.monkeyuser.com%s', $link[irand (1 + $#link)]; } } else { cluck sprintf 'Server return status %s with message: %s', $r->{status}, $r->{reason}; diff --git a/lib/BotLib/Weather.pm b/lib/BotLib/Weather.pm index fb01fe7..fee713a 100644 --- a/lib/BotLib/Weather.pm +++ b/lib/BotLib/Weather.pm @@ -59,7 +59,7 @@ sub Weather { decode_json ($r->{content}); }; - if ($EVAL_ERROR) { + unless (defined $fc) { carp "[WARN] openweathermap returns corrupted json: $EVAL_ERROR"; return undef; }; diff --git a/lib/JabberBot.pm b/lib/JabberBot.pm index 0bf6c0d..b5ab347 100644 --- a/lib/JabberBot.pm +++ b/lib/JabberBot.pm @@ -9,7 +9,7 @@ use warnings; use utf8; use open qw (:std :utf8); use English qw ( -no_match_vars ); -use Carp qw(carp); +use Carp qw (carp); use File::Path qw (make_path); use Hailo; use Net::Jabber::Bot; @@ -145,7 +145,8 @@ sub RunJabberBot { tls => 1, ssl_verify => 0, username => $c->{jabberbot}->{aleesa}->{authname}, -# threre is some nasty bug in module, so we have to set from_full explicitly + + # threre is some nasty bug in module, so we have to set from_full explicitly from_full => sprintf ( '%s@%s/%s', $c->{jabberbot}->{aleesa}->{room},