From 658ad6163550d593b10f7f2b424966b6425d8ccc Mon Sep 17 00:00:00 2001 From: Netkas Date: Mon, 13 Feb 2023 23:15:46 -0500 Subject: [PATCH] Added \TgBotLib\Objects > Game --- src/TgBotLib/Objects/Game.php | 176 ++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 src/TgBotLib/Objects/Game.php diff --git a/src/TgBotLib/Objects/Game.php b/src/TgBotLib/Objects/Game.php new file mode 100644 index 0000000..a755bbf --- /dev/null +++ b/src/TgBotLib/Objects/Game.php @@ -0,0 +1,176 @@ +title; + } + + /** + * Description of the game + * + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * Photo that will be displayed in the game message in chats. + * + * @return PhotoSize[] + */ + public function getPhoto(): array + { + return $this->photo; + } + + /** + * Optional. Brief description of the game or high scores included in the game message. Can be automatically + * edited to include current high scores for the game when the bot calls setGameScore, or manually edited using + * editMessageText. 0-4096 characters. + * + * @see https://core.telegram.org/bots/api#setgamescore + * @see https://core.telegram.org/bots/api#editmessagetext + * @return string|null + */ + public function getText(): ?string + { + return $this->text; + } + + /** + * Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. + * + * @return MessageEntity[]|null + */ + public function getTextEntities(): ?array + { + return $this->text_entities; + } + + /** + * Optional. Animation that will be displayed in the game message in chats. Upload via BotFather + * + * @see https://t.me/botfather + * @return Animation|null + */ + public function getAnimation(): ?Animation + { + return $this->animation; + } + + /** + * Returns an array representation of this object. + * + * @return array + */ + public function toArray(): array + { + $text_entities = null; + if ($this->text_entities) + { + foreach ($this->text_entities as $text_entity) + { + $text_entities[] = $text_entity->toArray(); + } + } + + $photo = null; + if ($this->photo) + { + foreach ($this->photo as $photo_item) + { + $photo[] = $photo_item->toArray(); + } + } + + return [ + 'title' => $this->title, + 'description' => $this->description, + 'photo' => $photo, + 'text' => $this->text, + 'text_entities' => $text_entities, + 'animation' => ($this->animation instanceof Animation) ? $this->animation->toArray() : null, + ]; + } + + /** + * Constructs object from an array representation + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $object = new self(); + + $photo = null; + if ($data['photo']) + { + foreach ($data['photo'] as $photo_item) + { + $photo[] = PhotoSize::fromArray($photo_item); + } + } + $text_entities = null; + if ($data['text_entities']) + { + foreach ($data['text_entities'] as $text_entity) + { + $text_entities[] = MessageEntity::fromArray($text_entity); + } + } + + $object->description = $data['description']; + $object->title = $data['title']; + $object->photo = $photo; + $object->text = $data['text'] ?? null; + $object->text_entities = $text_entities; + $object->animation = ($data['animation']) ? Animation::fromArray($data['animation']) : null; + + return $object; + } + } \ No newline at end of file