Simplify isAdmin method.

parent 37efce68
...@@ -538,16 +538,20 @@ class Telegram ...@@ -538,16 +538,20 @@ class Telegram
public function isAdmin($user_id = null) public function isAdmin($user_id = null)
{ {
if ($user_id === null && $this->update !== null) { if ($user_id === null && $this->update !== null) {
if (($message = $this->update->getMessage()) && ($from = $message->getFrom())) { //Try to figure out if the user is an admin
$user_id = $from->getId(); $update_methods = [
} elseif (($inline_query = $this->update->getInlineQuery()) && ($from = $inline_query->getFrom())) { 'getMessage',
$user_id = $from->getId(); 'getInlineQuery',
} elseif (($chosen_inline_result = $this->update->getChosenInlineResult()) && ($from = $chosen_inline_result->getFrom())) { 'getChosenInlineResult',
$user_id = $from->getId(); 'getCallbackQuery',
} elseif (($callback_query = $this->update->getCallbackQuery()) && ($from = $callback_query->getFrom())) { 'getEditedMessage',
$user_id = $from->getId(); ];
} elseif (($edited_message = $this->update->getEditedMessage()) && ($from = $edited_message->getFrom())) { foreach ($update_methods as $update_method) {
$user_id = $from->getId(); $object = call_user_func([$this->update, $update_method]);
if ($object !== null && $from = $object->getFrom()) {
$user_id = $from->getId();
break;
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment