From d386abf10724449e1426eadf29be2fe7f1be2d2f Mon Sep 17 00:00:00 2001 From: Mahdi Akrami Date: Sun, 28 Apr 2024 21:11:50 +0330 Subject: [PATCH] Fix PHP Error - Call to a member function getChat() on null in some case maybe users want to edit command and when the commend edited the $this->getMessage() return null and must use $this->getEditedMessage() to fix this issue --- src/Commands/AdminCommands/ChatsCommand.php | 2 +- src/Commands/AdminCommands/CleanupCommand.php | 2 +- src/Commands/AdminCommands/DebugCommand.php | 2 +- src/Commands/AdminCommands/SendtochannelCommand.php | 4 ++-- src/Commands/AdminCommands/WhoisCommand.php | 2 +- src/Commands/Command.php | 2 +- src/Commands/SystemCommand.php | 4 ++-- src/Commands/UserCommands/StartCommand.php | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Commands/AdminCommands/ChatsCommand.php b/src/Commands/AdminCommands/ChatsCommand.php index 42c545c63..d3d818a54 100644 --- a/src/Commands/AdminCommands/ChatsCommand.php +++ b/src/Commands/AdminCommands/ChatsCommand.php @@ -53,7 +53,7 @@ class ChatsCommand extends AdminCommand */ public function execute(): ServerResponse { - $message = $this->getMessage(); + $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost(); $chat_id = $message->getChat()->getId(); $text = trim($message->getText(true)); diff --git a/src/Commands/AdminCommands/CleanupCommand.php b/src/Commands/AdminCommands/CleanupCommand.php index 5be4975eb..221ed932d 100644 --- a/src/Commands/AdminCommands/CleanupCommand.php +++ b/src/Commands/AdminCommands/CleanupCommand.php @@ -365,7 +365,7 @@ public function executeNoDb(): ServerResponse */ public function execute(): ServerResponse { - $message = $this->getMessage(); + $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost(); $text = $message->getText(true); // Dry run? diff --git a/src/Commands/AdminCommands/DebugCommand.php b/src/Commands/AdminCommands/DebugCommand.php index 7c358b187..8a2fe80e4 100644 --- a/src/Commands/AdminCommands/DebugCommand.php +++ b/src/Commands/AdminCommands/DebugCommand.php @@ -52,7 +52,7 @@ class DebugCommand extends AdminCommand public function execute(): ServerResponse { $pdo = DB::getPdo(); - $message = $this->getMessage(); + $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost(); $chat = $message->getChat(); $text = strtolower($message->getText(true)); diff --git a/src/Commands/AdminCommands/SendtochannelCommand.php b/src/Commands/AdminCommands/SendtochannelCommand.php index f54704667..12fb82842 100644 --- a/src/Commands/AdminCommands/SendtochannelCommand.php +++ b/src/Commands/AdminCommands/SendtochannelCommand.php @@ -63,7 +63,7 @@ class SendtochannelCommand extends AdminCommand */ public function execute(): ServerResponse { - $message = $this->getMessage(); + $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost(); $chat_id = $message->getChat()->getId(); $user_id = $message->getFrom()->getId(); @@ -359,7 +359,7 @@ protected function publish(Message $message, $channel_id, $caption = null): stri */ public function executeNoDb(): ServerResponse { - $message = $this->getMessage(); + $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost(); $text = trim($message->getText(true)); if ($text === '') { diff --git a/src/Commands/AdminCommands/WhoisCommand.php b/src/Commands/AdminCommands/WhoisCommand.php index cb47d884d..033dbc87a 100644 --- a/src/Commands/AdminCommands/WhoisCommand.php +++ b/src/Commands/AdminCommands/WhoisCommand.php @@ -60,7 +60,7 @@ class WhoisCommand extends AdminCommand */ public function execute(): ServerResponse { - $message = $this->getMessage(); + $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost(); $chat_id = $message->getChat()->getId(); $command = $message->getCommand(); diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 235779640..f13905a6d 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -184,7 +184,7 @@ public function preExecute(): ServerResponse } if ($this->isPrivateOnly() && $this->removeNonPrivateMessage()) { - $message = $this->getMessage(); + $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost(); if ($user = $message->getFrom()) { return Request::sendMessage([ diff --git a/src/Commands/SystemCommand.php b/src/Commands/SystemCommand.php index d4b236ae9..8bdebf9c5 100644 --- a/src/Commands/SystemCommand.php +++ b/src/Commands/SystemCommand.php @@ -53,7 +53,7 @@ public function execute(): ServerResponse */ protected function executeActiveConversation(): ?ServerResponse { - $message = $this->getMessage(); + $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost(); if ($message === null) { return null; } @@ -84,7 +84,7 @@ protected function executeActiveConversation(): ?ServerResponse */ protected function executeDeprecatedSystemCommand(): ?ServerResponse { - $message = $this->getMessage(); + $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost(); if ($message === null) { return null; } diff --git a/src/Commands/UserCommands/StartCommand.php b/src/Commands/UserCommands/StartCommand.php index 7025bdc56..3f3d4b88f 100644 --- a/src/Commands/UserCommands/StartCommand.php +++ b/src/Commands/UserCommands/StartCommand.php @@ -47,7 +47,7 @@ class StartCommand extends UserCommand */ public function execute(): ServerResponse { - //$message = $this->getMessage(); + //$message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost(); //$chat_id = $message->getChat()->getId(); //$user_id = $message->getFrom()->getId();