Fix internal mechanics CanTalk() and replyMd() to work with external calls
This commit is contained in:
@@ -2,6 +2,7 @@ package Teapot::Bot::Object::ChatPermissions;
|
|||||||
# ABSTRACT: The base class for Telegram 'ChatPermissions' type objects
|
# ABSTRACT: The base class for Telegram 'ChatPermissions' type objects
|
||||||
use Carp qw(carp);
|
use Carp qw(carp);
|
||||||
use Mojo::Base 'Teapot::Bot::Object::Base';
|
use Mojo::Base 'Teapot::Bot::Object::Base';
|
||||||
|
use Teapot::Bot::Brain;
|
||||||
|
|
||||||
$Teapot::Bot::Object::ChatPermissions::VERSION = '0.022';
|
$Teapot::Bot::Object::ChatPermissions::VERSION = '0.022';
|
||||||
|
|
||||||
@@ -36,29 +37,29 @@ sub canTalk {
|
|||||||
|
|
||||||
if ($chatid < 0) {
|
if ($chatid < 0) {
|
||||||
# group chat
|
# group chat
|
||||||
my $chatobj = $self->getChat ({ 'chat_id' => $chatid });
|
my $chatobj = Teapot::Bot::Brain->getChat ($self, { 'chat_id' => $chatid });
|
||||||
|
|
||||||
# on api error, keep silence
|
# on api error, keep silence
|
||||||
unless ($chatobj) {
|
if ($chatobj == 0 || $chatobj->{error}) {
|
||||||
carp "Unable to get chat info for $chatid from telegram API";
|
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
|
# on api error, keep silence
|
||||||
unless ($chatobj) {
|
if ($myObj == 0 || $myObj->{error}) {
|
||||||
carp "Unable to get chat info for $chatid from telegram API";
|
carp "Unable to get chat info for $chatid from telegram API";
|
||||||
return 0;
|
return $can_talk;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $myid = $myObj->id;
|
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
|
# on api error, keep silence
|
||||||
unless ($me) {
|
if ($me == 0 || $me->{error}) {
|
||||||
carp 'Unable to get chat info for bot itself from telegram API';
|
carp 'Unable to get chat info for bot itself from telegram API';
|
||||||
return 0;
|
return $can_talk;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($me->{'status'} eq 'administrator') {
|
if ($me->{'status'} eq 'administrator') {
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ sub reply {
|
|||||||
|
|
||||||
my $chatid = $self->chat->id;
|
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});
|
return $self->_brain->sendMessage({chat_id => $chatid, text => $text});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ sub replyMd {
|
|||||||
|
|
||||||
my $chatid = $self->chat->id;
|
my $chatid = $self->chat->id;
|
||||||
|
|
||||||
if (Teapot::Bot::Object::ChatPermissions::canTalk ($self, $chatid)) {
|
if (Teapot::Bot::Object::ChatPermissions->canTalk ($self, $chatid)) {
|
||||||
my $send_args;
|
my $send_args;
|
||||||
$send_args->{text} = $text;
|
$send_args->{text} = $text;
|
||||||
$send_args->{parse_mode} = 'Markdown';
|
$send_args->{parse_mode} = 'Markdown';
|
||||||
|
|||||||
Reference in New Issue
Block a user