Skip to content

Commit

Permalink
Fix PHP Error - Call to a member function getChat() on null
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AkramiPro committed Apr 28, 2024
1 parent 57a649c commit d386abf
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Commands/AdminCommands/ChatsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/AdminCommands/CleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/AdminCommands/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/AdminCommands/SendtochannelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 === '') {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/AdminCommands/WhoisCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/SystemCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/UserCommands/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit d386abf

Please sign in to comment.