From 780ec4fe29828f1fd4f556ee2ebe60d4f90baf4a Mon Sep 17 00:00:00 2001 From: eleksir Date: Sat, 7 Jan 2023 16:53:47 +0300 Subject: [PATCH] Correctly handle successful response from banChatMember and restrictChatMember in BotLib.pm --- lib/BotLib.pm | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/BotLib.pm b/lib/BotLib.pm index e42db86..05d7a89 100644 --- a/lib/BotLib.pm +++ b/lib/BotLib.pm @@ -295,7 +295,9 @@ MYADMIN $reply = 'Я не буду себя банить.'; } } else { - $send_args->{user_id} = $me->id; + $send_args = undef; + $send_args->{chat_id} = 0 + $chatid; + $send_args->{user_id} = 0 + $me->id; $me = $self->getChatMember ($send_args); if ($me->{error}) { @@ -305,7 +307,9 @@ MYADMIN if ($me->status eq 'administrator') { # Проверим, что такой юзер есть в чятике - $send_args->{user_id} = $user_id_to_prosecute; + $send_args = undef; + $send_args->{chat_id} = 0 + $chatid; + $send_args->{user_id} = 0 + $user_id_to_prosecute; my $chatMember = $self->getChatMember ($send_args); if ($chatMember->{error}) { @@ -339,7 +343,8 @@ MYADMIN } } else { my $result; - + $send_args = undef; + $send_args->{chat_id} = 0 + $chatid; $send_args->{user_id} = 0 + $user_id_to_prosecute; $send_args->{until_date} = $time + time (); @@ -349,7 +354,10 @@ MYADMIN $result = $self->banChatMember ($send_args); } - if ($result->{error}) { + # Если всё хорошо, то возвращается true в формате JSON::PP::Boolean + if ((ref ($result) eq 'JSON::PP::Boolean') && ($result == JSON::PP::true)) { + $reply = 'Готово.'; + } elsif (defined ($result->{error}) && $result->{error}) { if ($action eq 'mute') { $log->error ( '[ERROR] Unable to call muteChatMember BotAPI method: ' . @@ -364,7 +372,11 @@ MYADMIN $reply = 'Что-то пошло не так, не получается забанить.'; } } else { - $reply = 'Готово.'; + $log->error ( + '[ERROR] Unable to call banChatMember/muteChatMember BotAPI method: ' . + Dumper ($result) + ); + $reply = 'Что-то пошло совсем не так.'; } } }