1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 19:51:11 +01:00

Some fixes

- Also remove empty assertion from edit bound method as it doesn't need here
This commit is contained in:
Mahdi 2023-08-04 11:52:37 +03:30
parent 4f0630a79d
commit 3aa6c68355
5 changed files with 52 additions and 9 deletions

View File

@ -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);
}
}

View File

@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace danog\MadelineProto\EventHandler;
@ -10,7 +12,7 @@ abstract class AbstractGameQuery extends AbstractQuery
public function __construct(MTProto $API, array $rawCallback)
{
parent::__construct($API);
parent::__construct($API, $rawCallback);
$this->gameShortName = $rawCallback['game_short_name'] ?? '';
}
}

View File

@ -1,8 +1,11 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace danog\MadelineProto\EventHandler;
use danog\MadelineProto\MTProto;
use danog\MadelineProto\ParseMode;
final class ChatButtonQuery extends AbstractButtonQuery
{
@ -41,8 +44,39 @@ final class ChatButtonQuery extends AbstractButtonQuery
'message' => $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));
}
}

View File

@ -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

View File

@ -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);