diff --git a/lib/BotLib.pm b/lib/BotLib.pm index 6f5753e..c25b2e8 100644 --- a/lib/BotLib.pm +++ b/lib/BotLib.pm @@ -9,8 +9,9 @@ use open qw (:std :utf8); use English qw ( -no_match_vars ); use Clone qw (clone); -use Math::Random::Secure qw (irand); use Data::Dumper qw (Dumper); +use Log::Any qw ($log); +use Math::Random::Secure qw (irand); use BotLib::Conf qw (LoadConf); use BotLib::Admin qw (@ForbiddenMessageTypes GetForbiddenTypes AddForbiddenType @@ -25,17 +26,18 @@ our @EXPORT_OK = qw (Command Highlight BotSleep IsCensored); my $c = LoadConf (); my $csign = $c->{telegrambot}->{csign}; -my $redismsg->{from} = 'telegram'; -$redismsg->{plugin} = 'telegram'; -$redismsg->{misc}->{answer} = 1; -$redismsg->{misc}->{csign} = "$c->{telegrambot}->{csign}"; + +my $redismsg->{from} = 'telegram'; +$redismsg->{plugin} = 'telegram'; +$redismsg->{misc}->{answer} = 1; +$redismsg->{misc}->{csign} = "$c->{telegrambot}->{csign}"; $redismsg->{misc}->{msg_format} = 0; -$redismsg->{misc}->{fwd_cnt} = 1; +$redismsg->{misc}->{fwd_cnt} = 1; sub Command { - my $self = shift; - my $msg = shift; - my $text = shift; + my $self = shift; + my $msg = shift; + my $text = shift; my $chatid = shift; my $reply; @@ -136,6 +138,8 @@ sub Command { } while (sleep 1); } + $log->debug ('Outgoing redis message: ' . Dumper ($rmsg)); + my $pubsub = $main::REDIS->pubsub; $pubsub->json ($c->{'redis_router_channel'})->notify ( @@ -270,8 +274,8 @@ MYADMIN { 'chat_id' => 0 + $chatid, 'user_id' => 0 + $user_id_to_mute, - 'until_date' => $time + time () - } + 'until_date' => $time + time (), + }, ); if ($result->{error}) { diff --git a/lib/RedisLib.pm b/lib/RedisLib.pm index a45640b..ece7447 100644 --- a/lib/RedisLib.pm +++ b/lib/RedisLib.pm @@ -6,9 +6,8 @@ use warnings; use utf8; use open qw (:std :utf8); +use Data::Dumper qw (Dumper); use Log::Any qw ($log); -# Чтобы "уж точно" использовать hiredis-биндинги, загрузим этот модуль перед Mojo::Redis -use Protocol::Redis::XS (); use Mojo::Redis (); use Mojo::Redis::Connection (); @@ -26,6 +25,8 @@ sub redis_parse_message { my $m = shift; my $message; + $log->debug ('Incoming redis message: ' . Dumper $m); + # Мы "не можем" отправлять сообщения в телеграм, если мы к нему не подключены # (конечно, можем, но Teapot-lib предполагает, что объектик с чатом - это его собственность, а городить свой что-то # не очень хочется) @@ -40,12 +41,12 @@ sub redis_parse_message { $message->{chat_id} = eval { 0 + $m->{chatid}; }; unless (defined $message->{chat_id}) { - log->error ('Incoming redis message is incorrect: chat id must be numeric value!'); + $log->error ('Incoming redis message is incorrect: chat id must be numeric value!'); return; } if ($message->{chat_id} == 0) { - log->error ('Incoming redis message is incorrect: chat id must not be equal 0!'); + $log->error ('Incoming redis message is incorrect: chat id must not be equal 0!'); return; } @@ -58,7 +59,7 @@ sub redis_parse_message { my $r = $main::TGM->sendMessage ($message); if ($r->{error}) { - log->error ("An error occured while sending message to chat $m->{chatid}"); + $log->error ("An error occured while sending message to chat $m->{chatid}"); } } diff --git a/lib/TelegramBot.pm b/lib/TelegramBot.pm index 3acd0a1..9a8a85e 100644 --- a/lib/TelegramBot.pm +++ b/lib/TelegramBot.pm @@ -7,7 +7,9 @@ use warnings; use utf8; use open qw (:std :utf8); use English qw ( -no_match_vars ); + use Clone qw (clone); +use Data::Dumper qw (Dumper); use Log::Any qw ($log); use Math::Random::Secure qw (irand); use Mojo::Base 'Teapot::Bot::Brain'; @@ -78,6 +80,8 @@ sub __cron { $rmsg->{userid} = "$enabledfortunechat"; $rmsg->{chatid} = "$enabledfortunechat"; + $log->debug ('Outgoing redis message: ' . Dumper ($rmsg)); + $pubsub->json ($c->{'redis_router_channel'})->notify ( $c->{'redis_router_channel'} => $rmsg, ); @@ -260,6 +264,15 @@ sub __on_msg { $rmsg->{chatid} = "$userid"; $rmsg->{misc}->{answer} = 1; + { + do { + my $ready = eval { $main::RCONN->is_connected; }; + last if ($ready); + } while (sleep 1); + } + + $log->debug ('Outgoing redis message: ' . Dumper ($rmsg)); + my $pubsub = $main::REDIS->pubsub; $pubsub->json ($c->{'redis_router_channel'})->notify ( @@ -347,6 +360,15 @@ sub __on_msg { $rmsg->{chatid} = "$chatid"; $rmsg->{misc}->{answer} = 1; + { + do { + my $ready = eval { $main::RCONN->is_connected; }; + last if ($ready); + } while (sleep 1); + } + + $log->debug ('Outgoing redis message: ' . Dumper ($rmsg)); + my $pubsub = $main::REDIS->pubsub; $pubsub->json ($c->{'redis_router_channel'})->notify ( @@ -396,6 +418,15 @@ sub __on_msg { $rmsg->{misc}->{answer} = 0; } + { + do { + my $ready = eval { $main::RCONN->is_connected; }; + last if ($ready); + } while (sleep 1); + } + + $log->debug ('Outgoing redis message: ' . Dumper ($rmsg)); + my $pubsub = $main::REDIS->pubsub; $pubsub->json ($c->{'redis_router_channel'})->notify (