diff --git a/lib/Teapot/Bot/Object/ChatPermissions.pm b/lib/Teapot/Bot/Object/ChatPermissions.pm index 01f2994..88cce62 100644 --- a/lib/Teapot/Bot/Object/ChatPermissions.pm +++ b/lib/Teapot/Bot/Object/ChatPermissions.pm @@ -2,6 +2,7 @@ package Teapot::Bot::Object::ChatPermissions; # ABSTRACT: The base class for Telegram 'ChatPermissions' type objects use Carp qw(carp); use Mojo::Base 'Teapot::Bot::Object::Base'; +use Teapot::Bot::Brain; $Teapot::Bot::Object::ChatPermissions::VERSION = '0.022'; @@ -36,29 +37,29 @@ sub canTalk { if ($chatid < 0) { # group chat - my $chatobj = $self->getChat ({ 'chat_id' => $chatid }); + my $chatobj = Teapot::Bot::Brain->getChat ($self, { '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->getMe (); + my $myObj = Teapot::Bot::Brain->getMe ($self); # 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->getChatMember ({ 'chat_id' => $chatid, 'user_id' => $myid }); + my $me = Teapot::Bot::Brain->getChatMember ($self, { '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') { diff --git a/lib/Teapot/Bot/Object/Message.pm b/lib/Teapot/Bot/Object/Message.pm index b5bf6ae..7f95f21 100644 --- a/lib/Teapot/Bot/Object/Message.pm +++ b/lib/Teapot/Bot/Object/Message.pm @@ -157,7 +157,7 @@ sub reply { my $chatid = $self->chat->id; - if (Teapot::Bot::Object::ChatPermissions::canTalk($self, $chatid)) { + if (Teapot::Bot::Object::ChatPermissions->canTalk($self, $chatid)) { return $self->_brain->sendMessage({chat_id => $chatid, text => $text}); } @@ -170,7 +170,7 @@ sub replyMd { my $chatid = $self->chat->id; - if (Teapot::Bot::Object::ChatPermissions::canTalk ($self, $chatid)) { + if (Teapot::Bot::Object::ChatPermissions->canTalk ($self, $chatid)) { my $send_args; $send_args->{text} = $text; $send_args->{parse_mode} = 'Markdown';