Make logging use features of Log::Any and log as it should be done via this module. Cleanup sample config.
This commit is contained in:
@@ -29,6 +29,7 @@ no Cwd;
|
||||
use Cwd::utf8 qw (chdir abs_path);
|
||||
use File::Basename qw (basename dirname);
|
||||
use File::Path qw (make_path);
|
||||
use Log::Any qw ($log);
|
||||
use Log::Any::Adapter;
|
||||
use Log::Any::For::Std;
|
||||
use POSIX qw (setgid setuid setsid);
|
||||
@@ -44,6 +45,7 @@ my $runAsUid = $UID;
|
||||
|
||||
my $piddir = '/var/run/' . basename (abs_path ($PROGRAM_NAME));
|
||||
my $C = LoadConf ();
|
||||
my $loglevel = $C->{'loglevel'} // 'notice';
|
||||
my $logfile;
|
||||
|
||||
if (defined $C->{'log'}) {
|
||||
@@ -92,7 +94,7 @@ if ($UID == 0) {
|
||||
}
|
||||
|
||||
if (defined $logfile) {
|
||||
Log::Any::Adapter->set ('File', $logfile);
|
||||
Log::Any::Adapter->set ('File', $logfile, log_level => $loglevel);
|
||||
|
||||
# Some annoying CHI logging events come with category set to CHI::Driver and log_level set to debug.
|
||||
# Until we use start using Log::Any native features and set whole loglevel accordingly, lets lower
|
||||
@@ -116,14 +118,24 @@ daemonize ();
|
||||
my $apath = abs_path $PROGRAM_NAME;
|
||||
|
||||
unless (defined $apath) {
|
||||
die "[FATAL] Unable to get abs_path: $OS_ERROR\n";
|
||||
$log->fatal ("[FATAL] Unable to get abs_path: $OS_ERROR\n");
|
||||
exit 1;
|
||||
};
|
||||
|
||||
# write pidfile
|
||||
my $pidfile = sprintf '%s/%s.pid', $piddir, basename $apath;
|
||||
warn "[INFO] Creating pidfile at $pidfile\n";
|
||||
open my $MYPID, '>', $pidfile or die "[FATAL] Error opening $pidfile: $OS_ERROR\n";
|
||||
print {$MYPID} $PID or die "[FATAL] Error writing to $pidfile: $OS_ERROR\n";
|
||||
$log->info ("[INFO] Creating pidfile at $pidfile");
|
||||
|
||||
open my $MYPID, '>', $pidfile or do {
|
||||
$log->fatal ("[FATAL] Error opening $pidfile: $OS_ERROR");
|
||||
exit 1;
|
||||
};
|
||||
|
||||
print {$MYPID} $PID or do {
|
||||
$log->fatal ("[FATAL] Error writing to $pidfile: $OS_ERROR");
|
||||
exit 1;
|
||||
};
|
||||
|
||||
close $MYPID; ## no critic (InputOutput::RequireCheckedSyscalls
|
||||
|
||||
local $SIG{INT} = \&__signal_handler;
|
||||
@@ -157,7 +169,8 @@ sub __fork {
|
||||
my $pid = fork;
|
||||
|
||||
unless (defined $pid) {
|
||||
die "[FATAL] Can't fork: $OS_ERROR\n";
|
||||
$log->fatal ("[FATAL] Can't fork: $OS_ERROR");
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if ($pid != 0) {
|
||||
@@ -168,7 +181,7 @@ sub __fork {
|
||||
}
|
||||
|
||||
sub __signal_handler {
|
||||
warn "[INFO] Caught a signal $OS_ERROR\n";
|
||||
$log->info ("[INFO] Caught a signal $OS_ERROR");
|
||||
|
||||
if (-f $pidfile) {
|
||||
unlink $pidfile;
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
{
|
||||
"admin" : {
|
||||
# store per-channel (per-conversation) settings
|
||||
"dir" : "data/admin"
|
||||
},
|
||||
|
||||
# cachedir used not only for caches but for somesettings and stats too
|
||||
# Cachedir used not only for caches but for some settings and stats too.
|
||||
"cachedir" : "data/cache",
|
||||
|
||||
"fortune" : {
|
||||
@@ -18,16 +13,15 @@
|
||||
},
|
||||
|
||||
"image": {
|
||||
"dir" : "data/image",
|
||||
"imgur" : {
|
||||
# see README.md about these settings - auth'ed search settings
|
||||
# See README.md about these settings - auth'ed search settings.
|
||||
"client-id" : "imgur api client id",
|
||||
"secret" : "secret for client id",
|
||||
"access_token" : "access token for querying imgur api",
|
||||
"refresh_token" : "token for refreshing access token"
|
||||
},
|
||||
"flickr" : {
|
||||
# see README.md about these settings - auth'ed search settings
|
||||
# See README.md about these settings - auth'ed search settings.
|
||||
"consumer_key" : "md5-like_hash",
|
||||
"consumer_secret" : "some_hash-like_string",
|
||||
"verifier": "some_hash-like_string"
|
||||
@@ -39,24 +33,31 @@
|
||||
"src": "data/lat.txt"
|
||||
},
|
||||
|
||||
# required for debugging reasons, if commented out or not exist, no debug logging appears at all
|
||||
"log" : "/var/log/aleesa-telegram-bot/debug.log",
|
||||
# Required for debugging reasons, if commented out or not exist, no debug logging appears at all.
|
||||
"log" : "/var/log/aleesa-telegram-bot/aleesa.log",
|
||||
|
||||
# openwatermap plugin
|
||||
# Verbosity can be trace, debug, info (inform), notice, warning (warn), error (err), critical (crit, fatal), alert, emergency.
|
||||
# Currently implemented debug, info, notice, warn, error, fatal. Notice is default logging level.
|
||||
"loglevel": "notice",
|
||||
|
||||
# Openwatermap plugin.
|
||||
"openweathermap" : {
|
||||
"appid" : "md5sum-like_string",
|
||||
},
|
||||
|
||||
# stuff for telegram itself
|
||||
# Stuff for telegram itself.
|
||||
"telegrambot" : {
|
||||
# directory with per-conversation "brains"
|
||||
|
||||
# Directory with per-conversation "brains".
|
||||
"braindir" : "data/telegrambot-brains",
|
||||
# prefix-sign for all commands. in many irc-bots (eggdrop/windrop) it is "." (dot), in sulci it was "!"
|
||||
# in telegram commands begin with "/" on the start of first (and only) line.
|
||||
|
||||
# Prefix-sign for all commands. In many irc-bots (eggdrop/windrop) it is "." (dot), in sulci it was "!".
|
||||
# In telegram commands begin with "/" on the start of first (and only) line. In case of this bot you can define what to use.
|
||||
"csign" : "!",
|
||||
|
||||
"token" : "Long_string_given_by_@BotFather"
|
||||
},
|
||||
|
||||
# unprivileged user to run this bot from
|
||||
# Unprivileged user to run this bot from.
|
||||
"user" : "unit",
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ sub Command {
|
||||
sleep (irand (2) + 1);
|
||||
$msg->replyMd ($reply);
|
||||
return;
|
||||
} elsif (substr ($text, 1) eq 'хэлп') {
|
||||
} elsif (substr ($text, 1) eq 'хэлп' || substr ($text, 1) eq 'хелп') {
|
||||
$reply = 'HALP!!!11';
|
||||
} elsif (substr ($text, 1) eq 'help' || substr ($text, 1) eq 'помощь') {
|
||||
$reply = << "MYHELP";
|
||||
|
||||
@@ -8,6 +8,7 @@ use open qw (:std :utf8);
|
||||
use English qw ( -no_match_vars );
|
||||
use Carp qw (cluck);
|
||||
use HTML::TokeParser;
|
||||
use Log::Any qw ($log);
|
||||
use Mojo::UserAgent;
|
||||
|
||||
use version; our $VERSION = qw (1.0);
|
||||
@@ -48,7 +49,7 @@ sub Buni {
|
||||
} while ($#{$a[0]} > 1);
|
||||
}
|
||||
} else {
|
||||
cluck sprintf 'Server return status %s with message: %s', $r->code, $r->message;
|
||||
$log->warn (sprintf '[WARN] Bunicomic server return status %s with message: %s', $r->code, $r->message);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
@@ -12,6 +12,7 @@ use English qw ( -no_match_vars );
|
||||
use Encode;
|
||||
use Carp qw (cluck);
|
||||
use HTML::TokeParser;
|
||||
use Log::Any qw ($log);
|
||||
use Mojo::Log;
|
||||
use Mojo::UserAgent::Cached;
|
||||
use POSIX qw (strftime);
|
||||
@@ -103,7 +104,7 @@ sub Drink {
|
||||
$ret = join "\n", @holyday;
|
||||
}
|
||||
} else {
|
||||
cluck sprintf 'Server return status %s with message: %s', $r->code, $r->message;
|
||||
$log->warn (sprintf '[WARN] Kakoysegodnyaprazdnik server return status %s with message: %s', $r->code, $r->message);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
@@ -9,6 +9,7 @@ use open qw (:std :utf8);
|
||||
use English qw ( -no_match_vars );
|
||||
use Carp qw (cluck croak);
|
||||
use File::Path qw (make_path);
|
||||
use Log::Any qw ($log);
|
||||
use Math::Random::Secure qw (irand);
|
||||
use SQLite_File;
|
||||
use BotLib::Conf qw (LoadConf);
|
||||
@@ -69,7 +70,7 @@ sub Fortune () {
|
||||
my $backingfile = sprintf '%s/fortune.sqlite', $dir;
|
||||
|
||||
tie my @array, 'SQLite_File', $backingfile || do {
|
||||
cluck "[ERROR] Unable to tie to $backingfile: $OS_ERROR";
|
||||
$log->error ("[ERROR] Unable to tie to $backingfile: $OS_ERROR");
|
||||
return '';
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use open qw (:std :utf8);
|
||||
use English qw ( -no_match_vars );
|
||||
use Carp qw (cluck croak);
|
||||
use File::Path qw (make_path);
|
||||
use Log::Any qw ($log);
|
||||
use Math::Random::Secure qw (irand);
|
||||
use SQLite_File;
|
||||
use BotLib::Conf qw (LoadConf);
|
||||
@@ -80,7 +81,7 @@ sub Friday () {
|
||||
my $backingfile = sprintf '%s/%s.sqlite', $dir, $dow[$today];
|
||||
|
||||
tie my @array, 'SQLite_File', $backingfile || do {
|
||||
cluck "[ERROR] Unable to tie to $backingfile: $OS_ERROR\n";
|
||||
$log->error ("[ERROR] Unable to tie to $backingfile: $OS_ERROR\n");
|
||||
return '';
|
||||
};
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ use utf8;
|
||||
use open qw (:std :utf8);
|
||||
use English qw ( -no_match_vars );
|
||||
use Carp qw (cluck);
|
||||
use Log::Any qw ($log);
|
||||
use Math::Random::Secure qw (irand);
|
||||
use Mojo::UserAgent;
|
||||
use BotLib::Image::Flickr qw (FlickrByTags);
|
||||
@@ -38,15 +39,15 @@ sub Kitty {
|
||||
};
|
||||
|
||||
unless (defined $jcat) {
|
||||
cluck "[ERROR] Unable to decode JSON: $EVAL_ERROR";
|
||||
$log->warn ("[WARN] Unable to decode JSON from thecatapi: $EVAL_ERROR");
|
||||
} else {
|
||||
if ($jcat->[0]->{url}) {
|
||||
my @cats = ('龴ↀ◡ↀ龴', '=^..^=', '≧◔◡◔≦ ','^ↀᴥↀ^' );
|
||||
my @cats = ('龴ↀ◡ↀ龴', '=^..^=', '≧◔◡◔≦ ','^ↀᴥↀ^');
|
||||
$ret = sprintf '[%s](%s)', $cats[irand ($#cats + 1)], $jcat->[0]->{url};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cluck sprintf 'Server return status %s with message: %s', $r->code, $r->message;
|
||||
$log->warn (sprintf '[WARN] Thecatapi server return status %s with message: %s', $r->code, $r->message);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
@@ -73,7 +74,7 @@ sub Fox {
|
||||
};
|
||||
|
||||
unless (defined $jfox) {
|
||||
cluck "[ERROR] Unable to decode JSON: $EVAL_ERROR";
|
||||
$log->warn ("[WARN] Unable to decode JSON from randomfox: $EVAL_ERROR");
|
||||
} else {
|
||||
if ($jfox->{image}) {
|
||||
$jfox->{image} =~ s/\\//xmsg;
|
||||
@@ -81,7 +82,7 @@ sub Fox {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cluck sprintf 'Server return status %s with message: %s', $r->code, $r->message;
|
||||
$log->warn (sprintf '[WARN] Randomfox server return status %s with message: %s', $r->code, $r->message);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
@@ -108,7 +109,7 @@ sub Oboobs {
|
||||
};
|
||||
|
||||
unless (defined $joboobs) {
|
||||
cluck "[ERROR] Unable to decode JSON: $EVAL_ERROR";
|
||||
$log->warn ("[WARN] Unable to decode JSON from oboobs: $EVAL_ERROR");
|
||||
} else {
|
||||
if ($joboobs->[0]->{preview}) {
|
||||
my @boobs = ('(. )( .)', '( . Y . )', '(o)(o)', '( @ )( @ )', '(.)(.)');
|
||||
@@ -116,7 +117,7 @@ sub Oboobs {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cluck sprintf 'Server return status %s with message: %s', $r->code, $r->message;
|
||||
$log->warn (sprintf '[WARN] Oboobs server return status %s with message: %s', $r->code, $r->message);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
@@ -143,7 +144,7 @@ sub Obutts {
|
||||
};
|
||||
|
||||
unless (defined $jobutts) {
|
||||
cluck "[ERROR] Unable to decode JSON: $EVAL_ERROR";
|
||||
$log->warn ("[ERROR] Unable to decode JSON from obutts: $EVAL_ERROR");
|
||||
} else {
|
||||
if ($jobutts->[0]->{preview}) {
|
||||
my @butts = ('(__(__)', '(_!_)', '(__.__)');
|
||||
@@ -151,7 +152,7 @@ sub Obutts {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cluck sprintf 'Server return status %s with message: %s', $r->code, $r->message;
|
||||
$log->warn (sprintf '[WARN] Obutts server return status %s with message: %s', $r->code, $r->message);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
@@ -10,6 +10,7 @@ use Carp qw (cluck);
|
||||
use CHI;
|
||||
use CHI::Driver::BerkeleyDB;
|
||||
use Digest::HMAC_SHA1 qw (hmac_sha1);
|
||||
use Log::Any qw ($log);
|
||||
use Math::Random::Secure qw (irand);
|
||||
use MIME::Base64;
|
||||
use Mojo::UserAgent;
|
||||
@@ -188,7 +189,7 @@ sub flickrAuthorization {
|
||||
if ($r->code == 302) {
|
||||
return $r->content->headers->location;
|
||||
} else {
|
||||
printf 'Something went wrong: %s %s', $r->code, $r->message;
|
||||
printf "Something went wrong: %s %s\n", $r->code, $r->message;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -335,19 +336,19 @@ sub flickrSearchByText {
|
||||
if (defined $response) {
|
||||
return $response;
|
||||
} else {
|
||||
cluck "Flickr api returns incorrect json: $r->message";
|
||||
$log->warn ("[WARN] Flickr api returns incorrect json: $r->message");
|
||||
return undef;
|
||||
}
|
||||
} else {
|
||||
cluck "Flickr api returns incorrect json: $r->message";
|
||||
$log->warn ("[WARN] Flickr api returns incorrect json: $r->message");
|
||||
return undef;
|
||||
}
|
||||
} else {
|
||||
cluck "Flickr api returns incorrect json: $r->message";
|
||||
$log->warn ("[WARN] Flickr api returns incorrect json: $r->message");
|
||||
return undef;
|
||||
}
|
||||
} else {
|
||||
cluck "HTTP status code not 200: $r->code, $r->message";
|
||||
$log->warn ("[WARN] Flickr api HTTP status code not 200: $r->code, $r->message");
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
@@ -442,19 +443,19 @@ sub flickrSearchByTags {
|
||||
if (defined $response) {
|
||||
return $response;
|
||||
} else {
|
||||
cluck "Flickr api returns incorrect json: $r->message";
|
||||
$log->warn ("[WARN] Flickr api returns incorrect json: $r->message");
|
||||
return undef;
|
||||
}
|
||||
} else {
|
||||
cluck "Flickr api returns incorrect json: $r->message";
|
||||
$log->warn ("[WARN] Flickr api returns incorrect json: $r->message");
|
||||
return undef;
|
||||
}
|
||||
} else {
|
||||
cluck "Flickr api returns incorrect json: $r->message";
|
||||
$log->warn ("[WARN] Flickr api returns incorrect json: $r->message");
|
||||
return undef;
|
||||
}
|
||||
} else {
|
||||
cluck "HTTP status code not 200: $r->code, $r->message";
|
||||
$log->warn ("[WARN] Flickr api HTTP status code not 200: $r->code, $r->message");
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
@@ -554,7 +555,7 @@ sub FlickrByTags {
|
||||
$item = sprintf 'https://live.staticflickr.com/%s/%s_%s_z.jpg', $item->{server}, $item->{id}, $item->{secret};
|
||||
return $item;
|
||||
} else {
|
||||
cluck 'Flickr api returns empty search result list';
|
||||
$log->notice ('[NOTICE] Flickr api returns empty search result list');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -587,7 +588,7 @@ sub FlickrByText {
|
||||
$item = sprintf 'https://live.staticflickr.com/%s/%s_%s_z.jpg', $item->{server}, $item->{id}, $item->{secret};
|
||||
return $item;
|
||||
} else {
|
||||
cluck 'Flickr api returns empty search result list';
|
||||
$log->notice ('[NOTICE] Flickr api returns empty search result list');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -9,6 +9,7 @@ use English qw ( -no_match_vars );
|
||||
use Carp qw (cluck);
|
||||
use CHI;
|
||||
use CHI::Driver::BerkeleyDB;
|
||||
use Log::Any qw ($log);
|
||||
use Math::Random::Secure qw (irand);
|
||||
use Mojo::UserAgent;
|
||||
|
||||
@@ -28,19 +29,19 @@ 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';
|
||||
$log->error ('[ERROR] 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';
|
||||
$log->error ('[ERROR] 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';
|
||||
$log->error ('[ERROR] 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';
|
||||
$log->warn ('[WARN] 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
|
||||
@@ -81,7 +82,7 @@ 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";
|
||||
$log->error ("[ERROR] Unable to refresh imgur token, please re-authorise app! or imgur experiencing api outage: $r->code $r->message");
|
||||
return undef;
|
||||
}
|
||||
|
||||
@@ -93,7 +94,7 @@ sub Imgur {
|
||||
$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";
|
||||
$log->warn ("[ERROR] Unable to refresh imgur access_token, unable to decode json: $EVAL_ERROR");
|
||||
return undef;
|
||||
}
|
||||
|
||||
@@ -130,19 +131,19 @@ sub Imgur {
|
||||
if ($#urls > 0) {
|
||||
return $urls[irand ($#urls + 1)];
|
||||
} else {
|
||||
cluck 'Imgur api returned empty result.';
|
||||
$log->notice ('[NOTICE] Imgur api returned empty result.');
|
||||
return undef;
|
||||
}
|
||||
} else {
|
||||
cluck "Unable to get results from imgur api: $r->message";
|
||||
$log->warn ("[WARN] Unable to get results from imgur api: $r->message");
|
||||
return undef;
|
||||
}
|
||||
} else {
|
||||
cluck "Unable to decode imgur api json: $EVAL_ERROR";
|
||||
$log->warn ("[WARN] Unable to decode imgur api json: $EVAL_ERROR");
|
||||
return undef;
|
||||
}
|
||||
} else {
|
||||
cluck "Unable to get results from imgur api: $r->code, $r->message";
|
||||
$log->warn ("[WARN] Unable to get results from imgur api: $r->code, $r->message");
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use English qw ( -no_match_vars );
|
||||
use Carp qw (cluck);
|
||||
use CHI;
|
||||
use CHI::Driver::BerkeleyDB;
|
||||
use Log::Any qw ($log);
|
||||
use BotLib::Conf qw (LoadConf);
|
||||
|
||||
use version; our $VERSION = qw (1.0);
|
||||
@@ -52,7 +53,7 @@ sub KarmaSet (@) {
|
||||
}
|
||||
|
||||
if ($cache->set ($phrase, $score, 'never') != $score) {
|
||||
cluck 'Cache error: unable to set karma.';
|
||||
$log->error ('[ERROR] Cache error: unable to set karma.');
|
||||
}
|
||||
|
||||
if ($score < -1 && (($score % (0 - $max)) + 1) == 0) {
|
||||
|
||||
@@ -11,6 +11,7 @@ use Carp qw (cluck);
|
||||
use File::Basename qw (dirname);
|
||||
use File::Path qw (make_path);
|
||||
use Hailo;
|
||||
use Log::Any qw ($log);
|
||||
use BotLib::Conf qw (LoadConf);
|
||||
|
||||
use version; our $VERSION = qw (1.0);
|
||||
@@ -49,12 +50,12 @@ sub Lat () {
|
||||
my $braindir = dirname $brain;
|
||||
|
||||
unless (-d $braindir) {
|
||||
cluck "[ERROR] No lat module data: $braindir is absent! Train lat first.";
|
||||
$log->error ("[ERROR] No lat module data: $braindir is absent! Train lat first.");
|
||||
return '';
|
||||
}
|
||||
|
||||
unless (-f $brain) {
|
||||
cluck "[ERROR] No lat module data: $brain is absent! Train lat first.";
|
||||
$log->error ("[ERROR] No lat module data: $brain is absent! Train lat first.");
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use open qw (:std :utf8);
|
||||
use English qw ( -no_match_vars );
|
||||
use Carp qw (cluck);
|
||||
use HTML::TokeParser;
|
||||
use Log::Any qw ($log);
|
||||
use Math::Random::Secure qw (irand);
|
||||
use Mojo::UserAgent;
|
||||
|
||||
@@ -51,7 +52,7 @@ sub Monkeyuser {
|
||||
$ret = sprintf '[MonkeyUser](https://www.monkeyuser.com%s)', $link [irand (1 + $#link)];
|
||||
}
|
||||
} else {
|
||||
cluck sprintf 'Server return status %s with message: %s', $r->{status}, $r->{reason};
|
||||
$log->warn (sprintf '[WARN] MonkeyUser server return status %s with message: %s', $r->{status}, $r->{reason});
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
@@ -9,6 +9,7 @@ use English qw ( -no_match_vars );
|
||||
use Carp qw (carp cluck);
|
||||
use CHI;
|
||||
use CHI::Driver::BerkeleyDB;
|
||||
use Log::Any qw ($log);
|
||||
use Mojo::Log;
|
||||
use Mojo::UserAgent::Cached;
|
||||
use BotLib::Conf qw (LoadConf);
|
||||
@@ -109,11 +110,11 @@ sub __weather {
|
||||
};
|
||||
|
||||
unless ($fc) {
|
||||
cluck "[WARN] openweathermap returns corrupted json: $EVAL_ERROR";
|
||||
$log->warn ("[WARN] openweathermap returns corrupted json: $EVAL_ERROR");
|
||||
return undef;
|
||||
};
|
||||
} else {
|
||||
cluck sprintf 'Server return status %s with message: %s', $r->code, $r->message;
|
||||
$log->warn (sprintf '[WARN] Server return status %s with message: %s', $r->code, $r->message);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use English qw ( -no_match_vars );
|
||||
use Carp qw (cluck carp);
|
||||
use File::Path qw (make_path);
|
||||
use Hailo;
|
||||
use Log::Any qw($log);
|
||||
use Math::Random::Secure qw (irand);
|
||||
use Mojo::Base 'Teapot::Bot::Brain';
|
||||
use BotLib::Admin qw (FortuneToggleList);
|
||||
@@ -72,7 +73,7 @@ sub __on_msg {
|
||||
my $myObj = $self->getMe ();
|
||||
|
||||
unless ($myObj) {
|
||||
carp '[ERROR] Unable to get chatid, API Error?';
|
||||
$log->error ('[ERROR] Unable to get chatid, API Error?');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,7 +106,7 @@ sub __on_msg {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
carp '[INFO] Unable to get chatid';
|
||||
$log->warn ('[INFO] Unable to get chatid');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -158,9 +159,9 @@ sub __on_msg {
|
||||
);
|
||||
|
||||
if ($chatid < 0) {
|
||||
carp "[INFO] Initialized brain for public chat $chatname ($chatid): $brainname";
|
||||
$log->info ("[INFO] Initialized brain for public chat $chatname ($chatid): $brainname");
|
||||
} else {
|
||||
carp "[INFO] Initialized brain for private chat $chatname ($chatid): $brainname";
|
||||
$log->info ("[INFO] Initialized brain for private chat $chatname ($chatid): $brainname");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +172,7 @@ sub __on_msg {
|
||||
}
|
||||
|
||||
my $text = $msg->text;
|
||||
carp sprintf ('[DEBUG] Private chat %s say to bot: %s', $vis_a_vi, $text) if $c->{debug};
|
||||
$log->debug (sprintf ('[DEBUG] Private chat %s say to bot: %s', $vis_a_vi, $text));
|
||||
my $reply = 'Давайте ещё пообщаемся, а то я ещё не научилась от вас плохому.';
|
||||
|
||||
if (substr ($text, 0, 1) eq $csign) {
|
||||
@@ -213,7 +214,7 @@ sub __on_msg {
|
||||
if (defined $reply) {
|
||||
$msg->typing ();
|
||||
sleep 1;
|
||||
carp sprintf ('[DEBUG] Private chat bot reply to %s: %s', $vis_a_vi, $reply) if $c->{debug};
|
||||
$log->debug (sprintf ('[DEBUG] Private chat bot reply to %s: %s', $vis_a_vi, $reply));
|
||||
$msg->reply ($reply);
|
||||
}
|
||||
# group chat
|
||||
@@ -221,26 +222,26 @@ sub __on_msg {
|
||||
my $reply;
|
||||
|
||||
if (IsCensored $msg) {
|
||||
carp sprintf '[INFO] In public chat %s (%s) message from %s was censored', $chatname, $chatid, $vis_a_vi;
|
||||
$log->info (sprintf '[INFO] In public chat %s (%s) message from %s was censored', $chatname, $chatid, $vis_a_vi);
|
||||
$self->deleteMessage ({chat_id => $chatid, message_id => $msg->{message_id}});
|
||||
}
|
||||
|
||||
# detect and log messages without text, noop here
|
||||
unless (defined $msg->text) {
|
||||
carp sprintf ('[DEBUG] No text in message from %s', $vis_a_vi) if $c->{debug};
|
||||
$log->debug (sprintf ('[DEBUG] No text in message from %s', $vis_a_vi));
|
||||
return;
|
||||
}
|
||||
|
||||
# we have text here! so potentially we can chit-chat
|
||||
my $text = $msg->text;
|
||||
carp sprintf ('[DEBUG] In public chat %s (%s) %s say: %s', $chatname, $chatid, $vis_a_vi, $text) if $c->{debug};
|
||||
$log->debug (sprintf ('[DEBUG] In public chat %s (%s) %s say: %s', $chatname, $chatid, $vis_a_vi, $text));
|
||||
|
||||
# are they quote something, maybe, us?
|
||||
if (defined ($msg->reply_to_message) &&
|
||||
defined ($msg->reply_to_message->from) &&
|
||||
defined ($msg->reply_to_message->from->username) &&
|
||||
($msg->reply_to_message->from->username eq $myusername)) {
|
||||
carp sprintf ('[DEBUG] In public chat %s (%s) %s quote us!', $chatname, $chatid, $vis_a_vi) if $c->{debug};
|
||||
$log->debug (sprintf ('[DEBUG] In public chat %s (%s) %s quote us!', $chatname, $chatid, $vis_a_vi));
|
||||
|
||||
# do not answer back if someone quote our new member greet
|
||||
if ((substr ($msg->reply_to_message->text, 0, 9) eq 'Дратути, ') &&
|
||||
@@ -335,10 +336,10 @@ sub __on_msg {
|
||||
|
||||
$msg->typing ();
|
||||
sleep (irand 2);
|
||||
carp sprintf ('[DEBUG] In public chat %s (%s) bot reply to %s: %s', $chatname, $chatid, $vis_a_vi, $reply) if $c->{debug};
|
||||
$log->debug (sprintf ('[DEBUG] In public chat %s (%s) bot reply to %s: %s', $chatname, $chatid, $vis_a_vi, $reply));
|
||||
$msg->reply ($reply);
|
||||
} else {
|
||||
carp sprintf ('[DEBUG] In public chat %s (%s) bot is not required to reply to %s', $chatname, $chatid, $vis_a_vi) if $c->{debug};
|
||||
$log->debug (sprintf ('[DEBUG] In public chat %s (%s) bot is not required to reply to %s', $chatname, $chatid, $vis_a_vi));
|
||||
}
|
||||
|
||||
# should be channel, so we can't talk
|
||||
@@ -356,7 +357,7 @@ sub init {
|
||||
|
||||
unless (-d $braindir) {
|
||||
make_path ($braindir, 0, 0755) or do { ## no critic (ValuesAndExpressions::ProhibitLeadingZeros)
|
||||
cluck "Unable to create $braindir: $OS_ERROR";
|
||||
$log->fatal ("[FATAL] Unable to create $braindir: $OS_ERROR");
|
||||
exit 1;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user