Also dump redis messages on debug loglevel

This commit is contained in:
eleksir
2022-04-23 14:38:06 +03:00
parent 93032dd35e
commit 1958f77e9c
3 changed files with 52 additions and 16 deletions

View File

@@ -9,8 +9,9 @@ use open qw (:std :utf8);
use English qw ( -no_match_vars ); use English qw ( -no_match_vars );
use Clone qw (clone); use Clone qw (clone);
use Math::Random::Secure qw (irand);
use Data::Dumper qw (Dumper); use Data::Dumper qw (Dumper);
use Log::Any qw ($log);
use Math::Random::Secure qw (irand);
use BotLib::Conf qw (LoadConf); use BotLib::Conf qw (LoadConf);
use BotLib::Admin qw (@ForbiddenMessageTypes GetForbiddenTypes AddForbiddenType use BotLib::Admin qw (@ForbiddenMessageTypes GetForbiddenTypes AddForbiddenType
@@ -25,6 +26,7 @@ our @EXPORT_OK = qw (Command Highlight BotSleep IsCensored);
my $c = LoadConf (); my $c = LoadConf ();
my $csign = $c->{telegrambot}->{csign}; my $csign = $c->{telegrambot}->{csign};
my $redismsg->{from} = 'telegram'; my $redismsg->{from} = 'telegram';
$redismsg->{plugin} = 'telegram'; $redismsg->{plugin} = 'telegram';
$redismsg->{misc}->{answer} = 1; $redismsg->{misc}->{answer} = 1;
@@ -136,6 +138,8 @@ sub Command {
} while (sleep 1); } while (sleep 1);
} }
$log->debug ('Outgoing redis message: ' . Dumper ($rmsg));
my $pubsub = $main::REDIS->pubsub; my $pubsub = $main::REDIS->pubsub;
$pubsub->json ($c->{'redis_router_channel'})->notify ( $pubsub->json ($c->{'redis_router_channel'})->notify (
@@ -270,8 +274,8 @@ MYADMIN
{ {
'chat_id' => 0 + $chatid, 'chat_id' => 0 + $chatid,
'user_id' => 0 + $user_id_to_mute, 'user_id' => 0 + $user_id_to_mute,
'until_date' => $time + time () 'until_date' => $time + time (),
} },
); );
if ($result->{error}) { if ($result->{error}) {

View File

@@ -6,9 +6,8 @@ use warnings;
use utf8; use utf8;
use open qw (:std :utf8); use open qw (:std :utf8);
use Data::Dumper qw (Dumper);
use Log::Any qw ($log); use Log::Any qw ($log);
# Чтобы "уж точно" использовать hiredis-биндинги, загрузим этот модуль перед Mojo::Redis
use Protocol::Redis::XS ();
use Mojo::Redis (); use Mojo::Redis ();
use Mojo::Redis::Connection (); use Mojo::Redis::Connection ();
@@ -26,6 +25,8 @@ sub redis_parse_message {
my $m = shift; my $m = shift;
my $message; my $message;
$log->debug ('Incoming redis message: ' . Dumper $m);
# Мы "не можем" отправлять сообщения в телеграм, если мы к нему не подключены # Мы "не можем" отправлять сообщения в телеграм, если мы к нему не подключены
# (конечно, можем, но Teapot-lib предполагает, что объектик с чатом - это его собственность, а городить свой что-то # (конечно, можем, но Teapot-lib предполагает, что объектик с чатом - это его собственность, а городить свой что-то
# не очень хочется) # не очень хочется)
@@ -40,12 +41,12 @@ sub redis_parse_message {
$message->{chat_id} = eval { 0 + $m->{chatid}; }; $message->{chat_id} = eval { 0 + $m->{chatid}; };
unless (defined $message->{chat_id}) { 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; return;
} }
if ($message->{chat_id} == 0) { 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; return;
} }
@@ -58,7 +59,7 @@ sub redis_parse_message {
my $r = $main::TGM->sendMessage ($message); my $r = $main::TGM->sendMessage ($message);
if ($r->{error}) { 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}");
} }
} }

View File

@@ -7,7 +7,9 @@ use warnings;
use utf8; use utf8;
use open qw (:std :utf8); use open qw (:std :utf8);
use English qw ( -no_match_vars ); use English qw ( -no_match_vars );
use Clone qw (clone); use Clone qw (clone);
use Data::Dumper qw (Dumper);
use Log::Any qw ($log); use Log::Any qw ($log);
use Math::Random::Secure qw (irand); use Math::Random::Secure qw (irand);
use Mojo::Base 'Teapot::Bot::Brain'; use Mojo::Base 'Teapot::Bot::Brain';
@@ -78,6 +80,8 @@ sub __cron {
$rmsg->{userid} = "$enabledfortunechat"; $rmsg->{userid} = "$enabledfortunechat";
$rmsg->{chatid} = "$enabledfortunechat"; $rmsg->{chatid} = "$enabledfortunechat";
$log->debug ('Outgoing redis message: ' . Dumper ($rmsg));
$pubsub->json ($c->{'redis_router_channel'})->notify ( $pubsub->json ($c->{'redis_router_channel'})->notify (
$c->{'redis_router_channel'} => $rmsg, $c->{'redis_router_channel'} => $rmsg,
); );
@@ -260,6 +264,15 @@ sub __on_msg {
$rmsg->{chatid} = "$userid"; $rmsg->{chatid} = "$userid";
$rmsg->{misc}->{answer} = 1; $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; my $pubsub = $main::REDIS->pubsub;
$pubsub->json ($c->{'redis_router_channel'})->notify ( $pubsub->json ($c->{'redis_router_channel'})->notify (
@@ -347,6 +360,15 @@ sub __on_msg {
$rmsg->{chatid} = "$chatid"; $rmsg->{chatid} = "$chatid";
$rmsg->{misc}->{answer} = 1; $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; my $pubsub = $main::REDIS->pubsub;
$pubsub->json ($c->{'redis_router_channel'})->notify ( $pubsub->json ($c->{'redis_router_channel'})->notify (
@@ -396,6 +418,15 @@ sub __on_msg {
$rmsg->{misc}->{answer} = 0; $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; my $pubsub = $main::REDIS->pubsub;
$pubsub->json ($c->{'redis_router_channel'})->notify ( $pubsub->json ($c->{'redis_router_channel'})->notify (