From 63304d6bb97a30ce264c6e721b73cc7ca62e6183 Mon Sep 17 00:00:00 2001 From: eleksir Date: Sun, 22 Nov 2020 16:29:26 +0300 Subject: [PATCH] First run fixes for fortune commands, also fixes for karma --- lib/botlib.pm | 6 +++--- lib/fortune.pm | 4 ++-- lib/telegrambot.pm | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/botlib.pm b/lib/botlib.pm index 349d103..00b763f 100644 --- a/lib/botlib.pm +++ b/lib/botlib.pm @@ -262,15 +262,15 @@ sub command { $reply = 'Шта?'; } elsif (substr ($text, 1) eq 'ver' || substr ($text, 1) eq 'version' || substr ($text, 1) eq 'версия') { $reply = 'Версия: Нуль.Чего-то_там.Чего-то_там'; - } elsif (substr ($text, 1, 2) eq 'w ' || substr ($text, 1, 2) eq 'п ') { + } elsif (length ($text) >= 2 && (substr ($text, 1, 2) eq 'w ' || substr ($text, 1, 2) eq 'п ')) { my $city = substr ($text, 3); $reply = weather ($city); } elsif (substr ($text, 1) eq 'lat' || substr ($text, 1) eq 'лат') { $reply = latAnswer (); - } elsif (substr ($text, 1, 6) eq 'karma ' || substr ($text, 1, 6) eq 'карма ' || substr($text, 1) eq 'karma' || substr($text, $1) eq 'карма') { + } elsif ((length ($text) >= 6 && (substr ($text, 1, 6) eq 'karma ' || substr ($text, 1, 6) eq 'карма ')) || substr($text, 1) eq 'karma' || substr($text, 1) eq 'карма') { my $mytext = ''; - if (length($text) >= 7) { + if (length($text) > 6) { $mytext = substr ($text, 7); chomp ($mytext); $mytext = trim ($mytext); diff --git a/lib/fortune.pm b/lib/fortune.pm index b0c7c36..eb95fc9 100644 --- a/lib/fortune.pm +++ b/lib/fortune.pm @@ -42,7 +42,7 @@ sub seed () { while (my $fortunefile = readdir ($srcdirhandle)) { my $srcfile = sprintf '%s/%s', $srcdir, $fortunefile; next unless (-f $srcfile); - next if (m/[\.|\$|\@]/); + next if ($fortunefile =~ m/\./); open (my $fh, '<', $srcfile) || croak "Unable to open $srcfile, $OS_ERROR\n"; # set correct phrase delimiter local $INPUT_RECORD_SEPARATOR = "\n%\n"; @@ -145,7 +145,7 @@ sub fortune_status ($) { if (defined $state && $state) { $phrase .= 'показываtтся.'; } else { - $phrase .= 'yt показываtтся.'; + $phrase .= 'не показывается.'; } untie %toggle; diff --git a/lib/telegrambot.pm b/lib/telegrambot.pm index bf33b7c..56fe300 100644 --- a/lib/telegrambot.pm +++ b/lib/telegrambot.pm @@ -41,10 +41,10 @@ sub __cron { # fortune mod my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime (time); - if ($hour = 8 && ($min >= 0 && $min <= 14)) { + if ($hour == 8 && ($min >= 0 && $min <= 14)) { foreach my $enabledfortunechat (fortune_toggle_list()) { my $send_args; - $send_args->{text} = sptintf "Сегодняшний день пройдёт под эгидой фразы:\n%s", fortune(); + $send_args->{text} = sprintf "Сегодняшний день пройдёт под эгидой фразы:\n%s", fortune(); $send_args->{chat_id} = $enabledfortunechat; Teapot::Bot::Brain::sendMessage ($self, $send_args); }