From b503fec76980434a869d9df86c803c544433e728 Mon Sep 17 00:00:00 2001 From: eleksir Date: Thu, 3 Feb 2022 00:29:26 +0300 Subject: [PATCH] Fix error handling in canTalk() --- lib/Teapot/Bot/Object/ChatPermissions.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Teapot/Bot/Object/ChatPermissions.pm b/lib/Teapot/Bot/Object/ChatPermissions.pm index 0b2a45d..ed2c66e 100644 --- a/lib/Teapot/Bot/Object/ChatPermissions.pm +++ b/lib/Teapot/Bot/Object/ChatPermissions.pm @@ -39,26 +39,26 @@ sub canTalk { my $chatobj = $self->_brain->getChat ({ 'chat_id' => $chatid }); # on api error, keep silence - unless ($chatobj) { + if ($chatobj == 0 || $chatobj->{error}) { carp "Unable to get chat info for $chatid from telegram API"; - return 0; + return $can_talk; } my $myObj = $self->_brain->getMe (); # on api error, keep silence - unless ($chatobj) { + if ($myObj == 0 || $myObj->{error}) { carp "Unable to get chat info for $chatid from telegram API"; - return 0; + return $can_talk; } my $myid = $myObj->id; my $me = $self->_brain->getChatMember ({ 'chat_id' => $chatid, 'user_id' => $myid }); # on api error, keep silence - unless ($me) { + if ($me == 0 || $me->{error}) { carp 'Unable to get chat info for bot itself from telegram API'; - return 0; + return $can_talk; } if ($me->{'status'} eq 'administrator') {