From 041ab3efeb4370d3e936f27b0c475b678c2f0688 Mon Sep 17 00:00:00 2001 From: eleksir Date: Tue, 9 Feb 2021 00:57:08 +0300 Subject: [PATCH] Fix fortune src filename check and another pack of style and natural language fixes --- bin/aleesa-telegram-bot | 2 +- bin/fortune_seed.pl | 8 ++++---- bin/friday_seed.pl | 8 ++++---- bin/train_lat.pl | 8 ++++---- confcheck.pl | 8 ++++---- lib/archeologist.pm | 4 ++-- lib/botlib.pm | 20 ++++++++++---------- lib/fisher.pm | 12 ++++++------ lib/fortune.pm | 8 ++++---- lib/karma.pm | 4 ++-- lib/lat.pm | 2 +- lib/telegrambot.pm | 27 +++++++++++++-------------- lib/weather.pm | 6 +++--- 13 files changed, 58 insertions(+), 59 deletions(-) diff --git a/bin/aleesa-telegram-bot b/bin/aleesa-telegram-bot index 0acfa11..0a116b9 100755 --- a/bin/aleesa-telegram-bot +++ b/bin/aleesa-telegram-bot @@ -72,7 +72,7 @@ if ($UID == 0) { } if (defined $logfile) { - my $logdir = dirname ($logfile); + my $logdir = dirname $logfile; unless (-d $logdir) { make_path ( diff --git a/bin/fortune_seed.pl b/bin/fortune_seed.pl index a0fd004..8757f1a 100644 --- a/bin/fortune_seed.pl +++ b/bin/fortune_seed.pl @@ -4,15 +4,15 @@ 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 version; our $VERSION = qw (1.0); my $workdir; # before we run, change working dir BEGIN { - use Cwd qw(chdir abs_path); + use Cwd qw (chdir abs_path); my @CWD = split /\//xms, abs_path ($PROGRAM_NAME); if ($#CWD > 1) { $#CWD = $#CWD - 2; } $workdir = join '/', @CWD; @@ -20,7 +20,7 @@ BEGIN { } use lib ("$workdir/lib", "$workdir/vendor_perl", "$workdir/vendor_perl/lib/perl5"); -use fortune qw(seed fortune); +use fortune qw (seed); use Carp; local $SIG{__DIE__} = sub { Carp::confess @_ }; diff --git a/bin/friday_seed.pl b/bin/friday_seed.pl index 5176009..2c61905 100644 --- a/bin/friday_seed.pl +++ b/bin/friday_seed.pl @@ -4,15 +4,15 @@ 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 version; our $VERSION = qw (1.0); my $workdir; # before we run, change working dir BEGIN { - use Cwd qw(chdir abs_path); + use Cwd qw (chdir abs_path); my @CWD = split /\//xms, abs_path ($PROGRAM_NAME); if ($#CWD > 1) { $#CWD = $#CWD - 2; } $workdir = join '/', @CWD; @@ -20,7 +20,7 @@ BEGIN { } use lib ("$workdir/lib", "$workdir/vendor_perl", "$workdir/vendor_perl/lib/perl5"); -use friday qw(seed); +use friday qw (seed); seed (); exit 0; diff --git a/bin/train_lat.pl b/bin/train_lat.pl index 4d7bf36..2d14997 100644 --- a/bin/train_lat.pl +++ b/bin/train_lat.pl @@ -4,15 +4,15 @@ 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 version; our $VERSION = qw (1.0); my $workdir; # before we run, change working dir BEGIN { - use Cwd qw(chdir abs_path); + use Cwd qw (chdir abs_path); my @CWD = split /\//xms, abs_path ($PROGRAM_NAME); if ($#CWD > 1) { $#CWD = $#CWD - 2; } $workdir = join '/', @CWD; @@ -20,7 +20,7 @@ BEGIN { } use lib ("$workdir/lib", "$workdir/vendor_perl", "$workdir/vendor_perl/lib/perl5"); -use lat qw(train); +use lat qw (train); train (); exit 0; diff --git a/confcheck.pl b/confcheck.pl index a75b446..6638b28 100755 --- a/confcheck.pl +++ b/confcheck.pl @@ -4,16 +4,16 @@ use 5.018; use strict; use warnings; use utf8; -use open qw(:std :utf8); -use English qw( -no_match_vars ); -use lib qw(./lib ./vendor_perl ./vendor_perl/lib/perl5); +use open qw (:std :utf8); +use English qw ( -no_match_vars ); +use lib qw (./lib ./vendor_perl ./vendor_perl/lib/perl5); use JSON::XS; use version; our $VERSION = qw (1.0); my $c = 'data/config.json'; open (my $C, '<', $c) or die "No conf at $c: $OS_ERROR\n"; -my $len = (stat ($c)) [7]; +my $len = (stat $c) [7]; my $json; my $readlen = read ($C, $json, $len); diff --git a/lib/archeologist.pm b/lib/archeologist.pm index 2848625..f7c257b 100644 --- a/lib/archeologist.pm +++ b/lib/archeologist.pm @@ -31,7 +31,7 @@ sub dig { 'ледяную глыбу', 'лунный грунт', 'мамонта', - 'мамонтенка', + 'мамонтёнка', 'метеорит', 'мумию фараона Тутанхамона', 'носки прапорщика (поставит в угол)', @@ -115,7 +115,7 @@ sub dig { $phrase .= sprintf '%s стал лучшим археологом, выкопав %s! возраст артефакта - %s лет!', $name, $artifact[irand ($#artifact + 1)], $artifact_age; } else { $phrase .= sprintf "Поздравляю, %s! Вы только что выкопали %s, возраст - %s лет!\n", $name, $artifact[irand ($#artifact + 1)], $artifact_age; - $phrase .= sprintf 'Извини %s, но на артефакт это не тянет! Однако, попытка хорошая!', $name; + $phrase .= sprintf 'Извини, %s, но на артефакт это не тянет! Однако, попытка хорошая!', $name; } return $phrase; diff --git a/lib/botlib.pm b/lib/botlib.pm index 6dd6992..99a93b9 100644 --- a/lib/botlib.pm +++ b/lib/botlib.pm @@ -52,7 +52,7 @@ sub command { my $text = shift; my $chatid = shift; my $reply; - my ($userid, $username, $fullname, $highlight, $visavi) = highlight ($msg); + my ($userid, $username, $fullname, $highlight, $visavi) = highlight $msg; if (substr ($text, 1) eq 'ping') { $reply = 'Pong.'; @@ -65,8 +65,8 @@ sub command { } elsif (substr ($text, 1) eq 'ver' || substr ($text, 1) eq 'version' || substr ($text, 1) eq 'версия') { $reply = 'Версия: Нуль.Чего-то_там.Чего-то_там'; } elsif (length ($text) >= 2 && (substr ($text, 1, 2) eq 'w ' || substr ($text, 1, 2) eq 'п ')) { - my $city = substr ($text, 3); - $reply = weather ($city); + my $city = substr $text, 3; + $reply = weather $city; } elsif (substr ($text, 1) eq 'cat' || substr ($text, 1) eq 'кис') { $reply = kitty (); $msg->typing (); @@ -79,9 +79,9 @@ sub command { my $mytext = ''; if (length($text) > 6) { - $mytext = substr ($text, 7); - chomp ($mytext); - $mytext = trim ($mytext); + $mytext = substr $text, 7; + chomp $mytext; + $mytext = trim $mytext; } else { $mytext = ''; } @@ -100,13 +100,13 @@ sub command { } elsif (substr ($text, 1) eq 'f ?' || substr ($text, 1) eq 'fortune ?' || substr ($text, 1) eq 'фортунка ?' || substr ($text, 1) eq 'ф ?') { $reply = fortune_status ($chatid); } elsif (substr ($text, 1) eq 'dig' || substr ($text, 1) eq 'копать') { - $reply = dig ($highlight); + $reply = dig $highlight; $msg->typing (); sleep (irand (2) + 1); $msg->replyMd ($reply); return; } elsif (substr ($text, 1) eq 'fish' || substr ($text, 1) eq 'fishing' || substr ($text, 1) eq 'рыба' || substr ($text, 1) eq 'рыбка' || substr ($text, 1) eq 'рыбалка' ) { - $reply = fish ($highlight); + $reply = fish $highlight; $msg->typing (); sleep (irand (2) + 1); $msg->replyMd ($reply); @@ -166,10 +166,10 @@ sub highlight { $fullname .= $msg->from->last_name; } - if (defined ($username)) { + if (defined $username) { $visavi .= '@' . $username; - if (defined ($fullname)) { + if (defined $fullname) { $highlight = "[$fullname](tg://user?id=$userid)"; $visavi .= ', ' . $fullname; } else { diff --git a/lib/fisher.pm b/lib/fisher.pm index 69d5627..3684501 100644 --- a/lib/fisher.pm +++ b/lib/fisher.pm @@ -32,7 +32,7 @@ sub fish { 'плотву', 'зубатку', 'солнечную рыбу', - 'cтарую шину', + 'старую шину', 'скользкую корягу', 'лампу джина', 'любовное послание в бутылке', @@ -70,7 +70,7 @@ sub fish { 'в поток', 'в озеро', 'в реку', - 'в северерный ледовитый океан', + 'в северный ледовитый океан', 'в индийский океан', 'в биде', 'в детский плавательный бассейн', @@ -92,7 +92,7 @@ sub fish { 'в черную дыру', 'дно Удомельского реактора', 'на Марс', - 'в соседнюю галактуку', + 'в соседнюю галактику', 'к соседу на балкон', 'далеко-далеко', 'далеко и надолго', @@ -101,7 +101,7 @@ sub fish { my @material = ( 'бамбуковую', - 'фиберглассовую', + 'фибергласовую', 'карбоновую', 'композитную', ); @@ -110,7 +110,7 @@ sub fish { my $success_probability = irand 100; my $weight = irand 7000; - my $phrase = sprintf "Вы забрасываете %s удочку %s.\nВы чувствуете поклевку и начинаете быстро тащить что-то.\n", $material[irand ($#material + 1)], $location[irand ($#location + 1)]; + my $phrase = sprintf "Вы забрасываете %s удочку %s.\nВы чувствуете поклёвку и начинаете быстро тащить что-то.\n", $material[irand ($#material + 1)], $location[irand ($#location + 1)]; if ($find_probability <= 20) { $phrase .= sprintf 'Черт, твоя рыбка сорвалась, %s! Не беда, может потом повезет?', $name; @@ -122,7 +122,7 @@ sub fish { if ($success_probability <= 25) { $phrase .= sprintf 'Ё-мое!!! А это ведь новый рекорд! Продолжай в том же духе, %s!', $name; } else { - $phrase .= sprintf 'Извини %s, но это не новый рекорд! Однако, хорошая попытка!', $name; + $phrase .= sprintf 'Извини, %s, но это не новый рекорд! Однако, хорошая попытка!', $name; } return $phrase; diff --git a/lib/fortune.pm b/lib/fortune.pm index cc7c9f0..f61d6fa 100644 --- a/lib/fortune.pm +++ b/lib/fortune.pm @@ -14,10 +14,10 @@ use SQLite_File; use conf qw (loadConf); use version; our $VERSION = qw (1.0); -use Exporter qw(import); -our @EXPORT_OK = qw(seed fortune fortune_toggle fortune_toggle_list fortune_status); +use Exporter qw (import); +our @EXPORT_OK = qw (seed fortune fortune_toggle fortune_toggle_list fortune_status); -my $c = loadConf(); +my $c = loadConf (); my $dir = $c->{fortune}->{dir}; my $srcdir = $c->{fortune}->{srcdir}; @@ -43,7 +43,7 @@ sub seed () { next; } - if ($fortunefile =~ m/\./) { + if ($fortunefile =~ m/^\.+$/) { next; } diff --git a/lib/karma.pm b/lib/karma.pm index 6a2505e..cbbbe64 100644 --- a/lib/karma.pm +++ b/lib/karma.pm @@ -14,9 +14,9 @@ use conf qw (loadConf); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw(karmaSet karmaGet); +our @EXPORT_OK = qw (karmaSet karmaGet); -my $c = loadConf(); +my $c = loadConf (); my $karmadir = $c->{karma}->{dir}; my $max = 5; diff --git a/lib/lat.pm b/lib/lat.pm index 31436c5..5daa9a3 100644 --- a/lib/lat.pm +++ b/lib/lat.pm @@ -39,7 +39,7 @@ sub train () { $lat->train ($srcfile); my ($tokens, $expressions) = ($lat->stats ())[0,1]; - printf "Total tokens: %s\nTotal expressins: %s\n", $tokens, $expressions; + printf "Total tokens: %s\nTotal expressions: %s\n", $tokens, $expressions; $lat->save (); return; } diff --git a/lib/telegrambot.pm b/lib/telegrambot.pm index e626609..f027c15 100644 --- a/lib/telegrambot.pm +++ b/lib/telegrambot.pm @@ -64,7 +64,7 @@ sub __on_msg { my $chatid; my $chatname = 'Noname chat'; # user sending message info - my ($userid, $username, $fullname, $highlight, $vis_a_vi) = highlight ($msg); + my ($userid, $username, $fullname, $highlight, $vis_a_vi) = highlight $msg; my $csign = $c->{telegrambot}->{csign}; unless ($myid) { @@ -93,7 +93,6 @@ sub __on_msg { if ($msg->chat->can ('id') && defined ($msg->chat->id)) { $chatid = $msg->chat->id; - my $group_talk = 0; if ($msg->chat->can ('username') && defined ($msg->chat->username)) { $chatname = $msg->chat->username ; @@ -142,14 +141,14 @@ sub __on_msg { $phrase = sprintf 'Дратути, %s. Представьтес, пожалуйста, и расскажите, что вас сюда привело.', $members[0]; } - botsleep ($msg); + botsleep $msg; $msg->replyMd ($phrase); return; } # lazy init chat-bot brains - unless (defined ($hailo->{$chatid})) { - my $brainname = sprintf ('%s/%s.brain.sqlite', $c->{telegrambot}->{braindir}, $chatid); + unless (defined $hailo->{$chatid}) { + my $brainname = sprintf '%s/%s.brain.sqlite', $c->{telegrambot}->{braindir}, $chatid; $hailo->{$chatid} = Hailo->new ( # we'll got file like this: data/telegrambot-brains/-1001332512695.brain.sqlite @@ -181,7 +180,7 @@ sub __on_msg { # is it karma adjustment? if (substr ($text, -2) eq '++' || substr ($text, -2) eq '--') { - my @arr = split(/\n/, $text); + my @arr = split /\n/, $text; if ($#arr < 1) { $reply = karmaSet ($chatid, trim (substr ($text, 0, -2)), substr ($text, -2)); @@ -195,13 +194,13 @@ sub __on_msg { if (defined ($str) && $str ne '') { $reply = $str; - $phrase = trim ($text); + $phrase = trim $text; while ($phrase =~ /[\.|\,|\?|\!]$/) { chop $phrase; } - $phrase = lc ($phrase); + $phrase = lc $phrase; if (fmatch (lc ($reply), $phrase)) { $reply = randomCommonPhrase (); @@ -221,7 +220,7 @@ sub __on_msg { my $reply; # detect and log messages without text, noop here - unless (defined ($msg->text)) { + unless (defined $msg->text) { carp sprintf ('[INFO] No text in message from %s', $vis_a_vi); return; } @@ -238,7 +237,7 @@ sub __on_msg { carp sprintf ('[DEBUG] In public chat %s (%s) %s quote us!', $chatname, $chatid, $vis_a_vi) if $c->{debug}; # remove our name from users reply, just in case my $pat1 = quotemeta ('@' . $myusername); - my $pat2 = quotemeta ($myfullname); + my $pat2 = quotemeta $myfullname; $phrase = $text; $phrase =~ s/$pat1//g; $phrase =~ s/$pat2//g; @@ -274,7 +273,7 @@ sub __on_msg { $reply = $hailo->{$msg->chat->id}->reply ($phrase); # karma adjustment } elsif (substr ($text, -2) eq '++' || substr ($text, -2) eq '--') { - my @arr = split(/\n/, $text); + my @arr = split /\n/, $text; if ($#arr < 1) { $reply = karmaSet ($chatid, trim (substr ($text, 0, -2)), substr ($text, -2)); @@ -290,20 +289,20 @@ sub __on_msg { if (defined ($reply) && $reply ne '') { # work a bit more on input phrase - $phrase = trim ($phrase); + $phrase = trim $phrase; while ($phrase =~ /[\.|\,|\?|\!]$/) { chop $phrase; } - $phrase = lc ($phrase); + $phrase = lc $phrase; if (fmatch (lc ($reply), $phrase)) { $reply = randomCommonPhrase (); } $msg->typing (); - sleep (irand (2)); + 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}; $msg->reply ($reply); } else { diff --git a/lib/weather.pm b/lib/weather.pm index ca5f514..d010df6 100644 --- a/lib/weather.pm +++ b/lib/weather.pm @@ -37,7 +37,7 @@ sub weather { $reply = sprintf ("Погода в городе %s, %s:\n%s, ветер %s %s м/c, температура %s°C, ощущается как %s°C, относительная влажность %s%%, давление %s мм.рт.с", $w->{name}, $w->{country}, - ucfirst ($w->{description}), + ucfirst $w->{description}, $w->{wind_direction}, $w->{wind_speed}, $w->{temperature_min}, @@ -49,7 +49,7 @@ sub weather { $reply = sprintf ("Погода в городе %s, %s:\n%s, ветер %s %s м/c, температура %s-%s°C, ощущается как %s°C, относительная влажность %s%%, давление %s мм.рт.ст", $w->{name}, $w->{country}, - ucfirst ($w->{description}), + ucfirst $w->{description}, $w->{wind_direction}, $w->{wind_speed}, $w->{temperature_min}, @@ -140,7 +140,7 @@ sub __weather { untie %cachetime; untie %cachedata; - # TODO: check all of this for existance + # TODO: check all of this for existence $w->{'name'} = $fc->{name}; $w->{'state'} = $fc->{state}; $w->{'country'} = $fc->{sys}->{country};