Add debug messages to some events

This commit is contained in:
eleksir
2020-09-21 02:13:20 +03:00
parent f0d8e90441
commit 376cbdfbe5

View File

@@ -37,6 +37,7 @@ sub __cron {
sub __on_msg { sub __on_msg {
my ($self, $msg) = @_; my ($self, $msg) = @_;
my $chatid; my $chatid;
$can_talk = 0;
unless ($myid) { unless ($myid) {
my $myObj = Telegram::Bot::Brain::getMe($self); my $myObj = Telegram::Bot::Brain::getMe($self);
@@ -47,6 +48,9 @@ sub __on_msg {
$chatid = $msg->{'chat'}->id; $chatid = $msg->{'chat'}->id;
my $group_talk = 0; my $group_talk = 0;
my $chatname = 'Noname chat';
$chatname = $msg->{'chat'}->username if ($msg->{'chat'}->can('username'));
# because of bot api restriction there is no events about changing permissions in chat sent to bot # because of bot api restriction there is no events about changing permissions in chat sent to bot
# so before sending any answer, we should check if we can do so # so before sending any answer, we should check if we can do so
@@ -66,12 +70,15 @@ sub __on_msg {
my $chatObj = getChatMember ($self, $chatid, $myid); my $chatObj = getChatMember ($self, $chatid, $myid);
if ($chatObj->{'status'} eq 'administrator') { if ($chatObj->{'status'} eq 'administrator') {
logger "can talk in $chatname";
$can_talk = 1; $can_talk = 1;
} else { } else {
logger "can talk in $chatname" if ($group_talk);
logger "can not talk in $chatname" unless ($group_talk);
$can_talk = $group_talk; $can_talk = $group_talk;
} }
} else { } else {
return; logger "mute in $chatid";
} }
my $phrase; my $phrase;
@@ -94,7 +101,9 @@ sub __on_msg {
if ($newcommer) { if ($newcommer) {
$msg->reply("Дратути, $newcommer. Представьтес, пожалуйста, и расскажите, что вас сюда привело."); $msg->reply("Дратути, $newcommer. Представьтес, пожалуйста, и расскажите, что вас сюда привело.");
logger "newcommer $newcommer in $chatid";
} else { } else {
logger "newcommer in $chatid";
$msg->reply("Дратути. Представьтес, пожалуйста, и расскажите, что вас сюда привело."); $msg->reply("Дратути. Представьтес, пожалуйста, и расскажите, что вас сюда привело.");
} }
@@ -142,7 +151,13 @@ sub __on_msg {
# group chat # group chat
} elsif (($msg->chat->type eq 'supergroup') or ($msg->chat->type eq 'group')) { } elsif (($msg->chat->type eq 'supergroup') or ($msg->chat->type eq 'group')) {
my $reply; my $reply;
return unless(defined($msg->text));
unless(defined($msg->text)) {
logger "No text in message";
logger Dumper($msg);
return;
}
my $text = $msg->text; my $text = $msg->text;
# sometimes shit happens? # sometimes shit happens?
return unless(defined($text)); return unless(defined($text));