From d0dea06b394d56c8038347dab1a130c39c7539a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=8EAhJ?= Date: Fri, 13 Oct 2023 15:54:44 +0330 Subject: [PATCH] add more updates --- src/EventHandler/BotCommands.php | 46 +++++++++++++++++ src/EventHandler/Channel/MessageForwards.php | 45 ++++++++++++++++ src/EventHandler/Command.php | 51 +++++++++++++++++++ src/EventHandler/Pinned.php | 39 ++++++++++++++ .../Pinned/PinnedChannelMessages.php | 37 ++++++++++++++ src/EventHandler/Pinned/PinnedMessages.php | 37 ++++++++++++++ 6 files changed, 255 insertions(+) create mode 100644 src/EventHandler/BotCommands.php create mode 100644 src/EventHandler/Channel/MessageForwards.php create mode 100644 src/EventHandler/Command.php create mode 100644 src/EventHandler/Pinned.php create mode 100644 src/EventHandler/Pinned/PinnedChannelMessages.php create mode 100644 src/EventHandler/Pinned/PinnedMessages.php diff --git a/src/EventHandler/BotCommands.php b/src/EventHandler/BotCommands.php new file mode 100644 index 000000000..3d1e3a09e --- /dev/null +++ b/src/EventHandler/BotCommands.php @@ -0,0 +1,46 @@ +. + * + * @author Amir Hossein Jafari + * @copyright 2016-2023 Amir Hossein Jafari + * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 + * @link https://docs.madelineproto.xyz MadelineProto documentation + */ + +namespace danog\MadelineProto\EventHandler; + +use danog\MadelineProto\MTProto; + +/** + * The [command set](https://core.telegram.org/api/bots/commands) of a certain bot in a certain chat has changed. + */ +final class BotCommands extends Update +{ + /** ID of the bot that changed its command set. */ + public readonly int $botId; + + /** The affected chat. */ + public readonly int $chatId; + + /** @var list New bot commands. */ + public readonly array $commands; + + /** @internal */ + public function __construct(MTProto $API, array $rawBotCommands) + { + parent::__construct($API); + $this->botId = $rawBotCommands['bot_id']; + $this->chatId = $API->getIdInternal($rawBotCommands['peer']); + $this->commands = array_map( + fn (array $command): Command => new Command($command), + $rawBotCommands['commands'] + ); + } +} diff --git a/src/EventHandler/Channel/MessageForwards.php b/src/EventHandler/Channel/MessageForwards.php new file mode 100644 index 000000000..58e33acf2 --- /dev/null +++ b/src/EventHandler/Channel/MessageForwards.php @@ -0,0 +1,45 @@ +. + * + * @author Amir Hossein Jafari + * @copyright 2016-2023 Amir Hossein Jafari + * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 + * @link https://docs.madelineproto.xyz MadelineProto documentation + */ + +namespace danog\MadelineProto\EventHandler\Channel; + +use danog\MadelineProto\MTProto; +use danog\MadelineProto\EventHandler\Update; +use danog\MadelineProto\MTProtoTools\DialogId; + +/** + * Represents the forward counter of a message in a channel has changed. + */ +final class MessageForwards extends Update +{ + /** Channel ID */ + public readonly int $chatId; + + /** ID of the message */ + public readonly int $id; + + /** New forward counter */ + public readonly int $forwards; + + /** @internal */ + public function __construct(MTProto $API, array $rawMessageViews) + { + parent::__construct($API); + $this->chatId = DialogId::fromSupergroupOrChannel($rawMessageViews['channel_id']); + $this->id = $rawMessageViews['id']; + $this->forwards = $rawMessageViews['forwards']; + } +} diff --git a/src/EventHandler/Command.php b/src/EventHandler/Command.php new file mode 100644 index 000000000..8e435d590 --- /dev/null +++ b/src/EventHandler/Command.php @@ -0,0 +1,51 @@ +. + * + * @author Daniil Gentili + * @copyright 2016-2023 Daniil Gentili + * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 + * @link https://docs.madelineproto.xyz MadelineProto documentation + */ + +namespace danog\MadelineProto\EventHandler; + +use JsonSerializable; +use ReflectionClass; +use ReflectionProperty; + +/** + * Represents a bot command that can be used in a chat. + */ +final class Command implements JsonSerializable +{ + /** `/command` name. */ + public readonly string $command; + + /** Description of the command. */ + public readonly string $description; + + /** @internal */ + public function __construct(array $rawCommand) + { + $this->command = $rawCommand['command']; + $this->description = $rawCommand['description']; + } + + /** @internal */ + public function jsonSerialize(): mixed + { + $res = ['_' => static::class]; + $refl = new ReflectionClass($this); + foreach ($refl->getProperties(ReflectionProperty::IS_PUBLIC) as $prop) { + $res[$prop->getName()] = $prop->getValue($this); + } + return $res; + } +} diff --git a/src/EventHandler/Pinned.php b/src/EventHandler/Pinned.php new file mode 100644 index 000000000..bf1ec5224 --- /dev/null +++ b/src/EventHandler/Pinned.php @@ -0,0 +1,39 @@ +. + * + * @author Amir Hossein Jafari + * @copyright 2016-2023 Amir Hossein Jafari + * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 + * @link https://docs.madelineproto.xyz MadelineProto documentation + */ + +namespace danog\MadelineProto\EventHandler; + +use danog\MadelineProto\MTProto; + +/** + * Represents messages s were pinned/unpinned. + */ +abstract class Pinned extends Update +{ + /** Whether the messages were pinned or unpinned. */ + public readonly bool $pinned; + + /** @var list List of identifiers of pinned messages. */ + public readonly array $ids; + + /** @internal */ + public function __construct(MTProto $API, array $rawPinned) + { + parent::__construct($API); + $this->pinned = $rawPinned['pinned']; + $this->ids = $rawPinned['messages']; + } +} diff --git a/src/EventHandler/Pinned/PinnedChannelMessages.php b/src/EventHandler/Pinned/PinnedChannelMessages.php new file mode 100644 index 000000000..5b4f7e0b2 --- /dev/null +++ b/src/EventHandler/Pinned/PinnedChannelMessages.php @@ -0,0 +1,37 @@ +. + * + * @author Amir Hossein Jafari + * @copyright 2016-2023 Amir Hossein Jafari + * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 + * @link https://docs.madelineproto.xyz MadelineProto documentation + */ + +namespace danog\MadelineProto\EventHandler\Pinned; + +use danog\MadelineProto\MTProto; +use danog\MadelineProto\EventHandler\Pinned; +use danog\MadelineProto\MTProtoTools\DialogId; + +/** + * Represents messages s were pinned/unpinned in a [channel/supergroup](https://core.telegram.org/api/channel). + */ +final class PinnedChannelMessages extends Pinned +{ + /** Channel ID. */ + public readonly int $chatId; + + /** @internal */ + public function __construct(MTProto $API, array $rawPinned) + { + parent::__construct($API, $rawPinned); + $this->chatId = DialogId::fromSupergroupOrChannel($rawPinned['channel_id']); + } +} diff --git a/src/EventHandler/Pinned/PinnedMessages.php b/src/EventHandler/Pinned/PinnedMessages.php new file mode 100644 index 000000000..35a4bcfd9 --- /dev/null +++ b/src/EventHandler/Pinned/PinnedMessages.php @@ -0,0 +1,37 @@ +. + * + * @author Amir Hossein Jafari + * @copyright 2016-2023 Amir Hossein Jafari + * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 + * @link https://docs.madelineproto.xyz MadelineProto documentation + */ + +namespace danog\MadelineProto\EventHandler\Pinned; + +use danog\MadelineProto\MTProto; +use danog\MadelineProto\EventHandler\Pinned; +use danog\MadelineProto\MTProtoTools\DialogId; + +/** + * Some messages were pinned in a chat. + */ +final class PinnedMessages extends Pinned +{ + /** Peer ID. */ + public readonly int $chatId; + + /** @internal */ + public function __construct(MTProto $API, array $rawPinned) + { + parent::__construct($API, $rawPinned); + $this->chatId = $API->getIdInternal($rawPinned['peer']); + } +}