Use check for defined value after eval(), style fixes, fix typo in sub name and var name
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}) {
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user