1-st run fixes after refactor
This commit is contained in:
@@ -37,17 +37,16 @@ sub GetForbiddenTypes {
|
||||
);
|
||||
|
||||
foreach (@ForbiddenMessageTypes) {
|
||||
my $type = $c->get ($_);
|
||||
my $type = $cache->get ($_);
|
||||
|
||||
if ($type) {
|
||||
$messageTypes->{$_} = 1;
|
||||
} else {
|
||||
unless (defined $type) {
|
||||
$c->set ($_, 1, 'never');
|
||||
$messageTypes->{$_} = 1;
|
||||
} else {
|
||||
$messageTypes->{$_} = 0;
|
||||
$cache->set ($_, 0, 'never');
|
||||
}
|
||||
|
||||
$messageTypes->{$_} = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,17 +92,16 @@ sub ListForbidden {
|
||||
);
|
||||
|
||||
foreach (@ForbiddenMessageTypes) {
|
||||
my $type = $c->get ($_);
|
||||
my $type = $cache->get ($_);
|
||||
|
||||
if ($type) {
|
||||
push @list, sprintf 'Тип сообщения %s удаляется', $_;
|
||||
} else {
|
||||
unless (defined $type) {
|
||||
push @list, sprintf 'Тип сообщения %s удаляется', $_;
|
||||
$c->set ($_, 1, 'never');
|
||||
} else {
|
||||
push @list, sprintf 'Тип сообщения %s не удаляется', $_;
|
||||
$cache->set ($_, 0, 'never');
|
||||
}
|
||||
|
||||
push @list, sprintf 'Тип сообщения %s не удаляется', $_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,9 +189,13 @@ sub PluginStatus (@) {
|
||||
|
||||
my $state = $cache->get ($plugin);
|
||||
|
||||
if (defined $state && $state) {
|
||||
if ($state) {
|
||||
$phrase .= 'включён.';
|
||||
} else {
|
||||
unless (defined $state) {
|
||||
$cache->set ($plugin, 0, 'never');
|
||||
}
|
||||
|
||||
$phrase .= 'выключен.';
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ sub Buni {
|
||||
|
||||
for (1..3) {
|
||||
my $ua = Mojo::UserAgent->new->connect_timeout (3);
|
||||
$ua->max_redirects(3);
|
||||
$r = $ua->get ('http://www.bunicomic.com/?random&nocache=1')->result;
|
||||
|
||||
if ($r->is_success) {
|
||||
|
||||
@@ -15,7 +15,7 @@ use BotLib::Conf qw (LoadConf);
|
||||
|
||||
use version; our $VERSION = qw (1.0);
|
||||
use Exporter qw (import);
|
||||
our @EXPORT_OK = qw (seed friday);
|
||||
our @EXPORT_OK = qw (Seed Friday);
|
||||
|
||||
my $c = LoadConf ();
|
||||
my $dir = $c->{friday}->{dir};
|
||||
|
||||
@@ -9,7 +9,7 @@ use English qw ( -no_match_vars );
|
||||
use Carp qw (cluck);
|
||||
use Math::Random::Secure qw (irand);
|
||||
use Mojo::UserAgent;
|
||||
use BotLIb::Image::Flickr qw (FlickrByTags);
|
||||
use BotLib::Image::Flickr qw (FlickrByTags);
|
||||
use BotLib::Image::Imgur qw (Imgur);
|
||||
use BotLib::Util qw (urlencode);
|
||||
|
||||
@@ -17,7 +17,7 @@ use version; our $VERSION = qw (1.0);
|
||||
use Exporter qw (import);
|
||||
our @EXPORT_OK = qw (Kitty Fox Oboobs Obutts Rabbit Owl);
|
||||
|
||||
sub kitty {
|
||||
sub Kitty {
|
||||
my $r;
|
||||
my $ret = 'Нету кошечек, все разбежались.';
|
||||
|
||||
@@ -52,7 +52,7 @@ sub kitty {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub fox {
|
||||
sub Fox {
|
||||
my $r;
|
||||
my $ret = 'Нету лисичек, все разбежались.';
|
||||
|
||||
@@ -87,7 +87,7 @@ sub fox {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub oboobs {
|
||||
sub Oboobs {
|
||||
my $r;
|
||||
my $ret = 'Нету cисичек, все разбежались.';
|
||||
|
||||
@@ -122,7 +122,7 @@ sub oboobs {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub obutts {
|
||||
sub Obutts {
|
||||
my $r;
|
||||
my $ret = 'Нету попок, все разбежались.';
|
||||
|
||||
@@ -179,7 +179,7 @@ sub rabbit_imgur {
|
||||
}
|
||||
}
|
||||
|
||||
sub rabbit {
|
||||
sub Rabbit {
|
||||
# rabbit, but bunny
|
||||
my $url = FlickrByTags ('animal,bunny');
|
||||
|
||||
@@ -190,7 +190,7 @@ sub rabbit {
|
||||
}
|
||||
}
|
||||
|
||||
sub owl {
|
||||
sub Owl {
|
||||
my $url = FlickrByTags ('bird,owl');
|
||||
|
||||
if (defined $url) {
|
||||
|
||||
@@ -185,10 +185,10 @@ sub flickrAuthorization {
|
||||
my $ua = Mojo::UserAgent->new->connect_timeout (5);
|
||||
my $r = $ua->get ($url)->result;
|
||||
|
||||
if ($r->is_success) {
|
||||
return $r->url;
|
||||
if ($r->code == 302) {
|
||||
return $r->content->headers->location;
|
||||
} else {
|
||||
say "Something went wrong: $r->code $r->message"; ## no critic (InputOutput::RequireCheckedSyscalls)
|
||||
printf 'Something went wrong: %s %s', $r->code, $r->message;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -471,7 +471,7 @@ sub FlickrInit {
|
||||
my $flickr_request_token_secret = $cache->get ('flickr_request_token_secret');
|
||||
|
||||
unless (defined $flickr_request_token || defined $flickr_request_token_secret) {
|
||||
say "Looks like there is no request token or request token secret in config db."; ## no critic (InputOutput::RequireCheckedSyscalls)
|
||||
say 'Looks like there is no request token or request token secret in config db.'; ## no critic (InputOutput::RequireCheckedSyscalls)
|
||||
say 'Please remove verifier settings from config.json and run this script again.'; ## no critic (InputOutput::RequireCheckedSyscalls)
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ use Exporter qw (import);
|
||||
our @EXPORT_OK = qw (Imgur);
|
||||
|
||||
my $c = LoadConf ();
|
||||
my $cachedir = $c->{cachedir};
|
||||
|
||||
sub Imgur {
|
||||
my $tag = shift;
|
||||
@@ -27,20 +28,20 @@ sub Imgur {
|
||||
my $search_url = 'https://api.imgur.com/3/gallery/search/';
|
||||
|
||||
my $imgur_client_id = $c->{image}->{imgur}->{client_id} // do {
|
||||
cluck "No client_id specified in config for imgur module";
|
||||
cluck 'No client_id specified in config for imgur module';
|
||||
return undef;
|
||||
};
|
||||
my $imgur_client_secret = $c->{image}->{imgur}->{client_secret} // do {
|
||||
cluck "No client_secret specified in config for imgur module";
|
||||
cluck 'No client_secret specified in config for imgur module';
|
||||
return undef;
|
||||
};
|
||||
my $imgur_access_token = $c->{image}->{imgur}->{access_token} // do {
|
||||
cluck "No access_token specified in config for imgur module";
|
||||
cluck 'No access_token specified in config for imgur module';
|
||||
return undef;
|
||||
};
|
||||
my $imgur_refresh_token = $c->{image}->{imgur}->{refresh_token} // do {
|
||||
cluck "No refresh_token specified in config for imgur module";
|
||||
}
|
||||
cluck 'No refresh_token specified in config for imgur module';
|
||||
};
|
||||
|
||||
# N.B. Both imgur_access_token and imgur_refresh_token time to time can change, so we need
|
||||
# some place where we can store new values
|
||||
@@ -81,7 +82,6 @@ sub Imgur {
|
||||
|
||||
unless ($r->is_success) {
|
||||
cluck "Unable to refresh imgur token, please re-authorise app! or imgur experiencing api outage: $r->code $r->message";
|
||||
untie %secret;
|
||||
return undef;
|
||||
}
|
||||
|
||||
@@ -89,12 +89,11 @@ sub Imgur {
|
||||
|
||||
if (defined $refresh) {
|
||||
$imgur_refresh_token = $refresh->{refresh_token};
|
||||
$secret{imgur_refresh_token} = $refresh->{refresh_token};
|
||||
$cache->set ('refresh_token', $refresh->{refresh_token}, 'never');
|
||||
$imgur_access_token = $refresh->{access_token};
|
||||
$secret{imgur_access_token} = $refresh->{access_token};
|
||||
$cache->set ('imgur_access_token', $refresh->{access_token}, 'never');
|
||||
} else {
|
||||
cluck "Unable to refresh imgur access_token, unable to decode json: $EVAL_ERROR";
|
||||
untie %secret;
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ use Carp qw (cluck);
|
||||
use File::Basename qw (dirname);
|
||||
use File::Path qw (make_path);
|
||||
use Hailo;
|
||||
use BotLib::Conf qw (loadConf);
|
||||
use BotLib::Conf qw (LoadConf);
|
||||
|
||||
use version; our $VERSION = qw (1.0);
|
||||
use Exporter qw (import);
|
||||
|
||||
@@ -16,12 +16,12 @@ use BotLib::Util qw (trim urlencode);
|
||||
|
||||
use version; our $VERSION = qw (1.0);
|
||||
use Exporter qw (import);
|
||||
our @EXPORT_OK = qw (weather);
|
||||
our @EXPORT_OK = qw (Weather);
|
||||
|
||||
my $c = LoadConf ();
|
||||
my $cachedir = $c->{cachedir};
|
||||
|
||||
sub weather {
|
||||
sub Weather {
|
||||
my $city = shift;
|
||||
$city = trim $city;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user