From 3aa6c68355adc665e480c81c1316efc867ca07c8 Mon Sep 17 00:00:00 2001 From: Mahdi Date: Fri, 4 Aug 2023 11:52:37 +0330 Subject: [PATCH] Some fixes - Also remove empty assertion from edit bound method as it doesn't need here --- src/EventHandler/AbstractButtonQuery.php | 6 ++++ src/EventHandler/AbstractGameQuery.php | 6 ++-- src/EventHandler/ChatButtonQuery.php | 40 ++++++++++++++++++++++-- src/EventHandler/Message.php | 5 +-- src/MTProtoTools/UpdateHandler.php | 4 +-- 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/EventHandler/AbstractButtonQuery.php b/src/EventHandler/AbstractButtonQuery.php index f11f34fbd..76e142bf2 100644 --- a/src/EventHandler/AbstractButtonQuery.php +++ b/src/EventHandler/AbstractButtonQuery.php @@ -2,6 +2,12 @@ namespace danog\MadelineProto\EventHandler; +use danog\MadelineProto\MTProto; + abstract class AbstractButtonQuery extends AbstractQuery { + public function __construct(MTProto $API, array $rawCallback) + { + parent::__construct($API, $rawCallback); + } } diff --git a/src/EventHandler/AbstractGameQuery.php b/src/EventHandler/AbstractGameQuery.php index 4a5ecd2f3..2b8915f19 100644 --- a/src/EventHandler/AbstractGameQuery.php +++ b/src/EventHandler/AbstractGameQuery.php @@ -1,4 +1,6 @@ -gameShortName = $rawCallback['game_short_name'] ?? ''; } } diff --git a/src/EventHandler/ChatButtonQuery.php b/src/EventHandler/ChatButtonQuery.php index 338174e6e..b78988dde 100644 --- a/src/EventHandler/ChatButtonQuery.php +++ b/src/EventHandler/ChatButtonQuery.php @@ -1,8 +1,11 @@ - $message, 'alert' => $alert, 'url' => $url, - 'cache_time' => $cacheTime - ] + 'cache_time' => $cacheTime, + ], ); } + + /** + * Edit message text. + * + * @param string $message New message + * @param ParseMode $parseMode Whether to parse HTML or Markdown markup in the message + * @param array|null $replyMarkup Reply markup for inline keyboards + * @param int|null $scheduleDate Scheduled message date for scheduled messages + * @param bool $noWebpage Disable webpage preview + */ + public function edit( + string $message, + ?array $replyMarkup = null, + ParseMode $parseMode = ParseMode::TEXT, + ?int $scheduleDate = null, + bool $noWebpage = false + ): Message { + $result = $this->getClient()->methodCallAsyncRead( + 'messages.editMessage', + [ + 'peer' => $this->chatId, + 'id' => $this->messageId, + 'message' => $message, + 'reply_markup' => $replyMarkup, + 'parse_mode' => $parseMode, + 'schedule_date' => $scheduleDate, + 'no_webpage' => $noWebpage, + ], + ); + return $this->getClient()->wrapMessage($this->getClient()->extractMessage($result)); + } } diff --git a/src/EventHandler/Message.php b/src/EventHandler/Message.php index 6845edffa..998dd755e 100644 --- a/src/EventHandler/Message.php +++ b/src/EventHandler/Message.php @@ -17,7 +17,6 @@ use danog\MadelineProto\EventHandler\Media\Voice; use danog\MadelineProto\MTProto; use danog\MadelineProto\ParseMode; use danog\MadelineProto\StrTools; -use Webmozart\Assert\Assert; /** * Represents an incoming or outgoing message. @@ -290,23 +289,25 @@ abstract class Message extends AbstractMessage * * @param string $message New message * @param ParseMode $parseMode Whether to parse HTML or Markdown markup in the message + * @param array|null $replyMarkup Reply markup for inline keyboards * @param int|null $scheduleDate Scheduled message date for scheduled messages * @param bool $noWebpage Disable webpage preview * */ public function edit( string $message, + ?array $replyMarkup = null, ParseMode $parseMode = ParseMode::TEXT, ?int $scheduleDate = null, bool $noWebpage = false ): Message { - Assert::notEmpty($this->message); $result = $this->getClient()->methodCallAsyncRead( 'messages.editMessage', [ 'peer' => $this->chatId, 'id' => $this->id, 'message' => $message, + 'reply_markup' => $replyMarkup, 'parse_mode' => $parseMode, 'schedule_date' => $scheduleDate, 'no_webpage' => $noWebpage diff --git a/src/MTProtoTools/UpdateHandler.php b/src/MTProtoTools/UpdateHandler.php index 00b6d1fa0..5a819107c 100644 --- a/src/MTProtoTools/UpdateHandler.php +++ b/src/MTProtoTools/UpdateHandler.php @@ -350,13 +350,13 @@ trait UpdateHandler private function wrapQuery(array $callback): ?AbstractQuery { if ($callback['_'] == 'updateBotCallbackQuery') { - if (!isset($callback['game_short_name']) && !empty($callback['game_short_name'])) { + if (isset($callback['game_short_name']) && !empty($callback['game_short_name'])) { return new ChatGameQuery($this, $callback); } return new ChatButtonQuery($this, $callback); } if ($callback['_'] == 'updateInlineBotCallbackQuery') { - if (!isset($callback['game_short_name']) && !empty($callback['game_short_name'])) { + if (isset($callback['game_short_name']) && !empty($callback['game_short_name'])) { return new InlineGameQuery($this, $callback); } return new InlineButtonQuery($this, $callback);