From b4e0f62e994763a958512af443fa50c1fa9c6d5b Mon Sep 17 00:00:00 2001 From: Netkas Date: Mon, 10 Apr 2023 19:38:06 -0400 Subject: [PATCH] Optional. Sticker set thumbnail in the .WEBP, .TGS, or .WEBM format https://git.n64.cc/nosial/libs/tgbot/-/issues/2 --- CHANGELOG.md | 1 + src/TgBotLib/Objects/Telegram/StickerSet.php | 157 +++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 src/TgBotLib/Objects/Telegram/StickerSet.php diff --git a/CHANGELOG.md b/CHANGELOG.md index b1920c9..88f929e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This update accompanies the release of the [Telegram Bot API 6.6](https://core.t See [uploadStickerFile](https://core.telegram.org/bots/api#uploadstickerfile) for more information. * Added method `\TgBotLib\Bot > setCustomEmojiStickerSetThumbnail()` to set the thumbnail of a sticker set. See [setCustomEmojiStickerSetThumbnail](https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail) for more information. + * Added object `\TgBotLib\Objects\Telegram > StickerSet` to represent a sticker set. ### Changed * Removed unused `__destruct()` method from `\TgBotLib\Bot` diff --git a/src/TgBotLib/Objects/Telegram/StickerSet.php b/src/TgBotLib/Objects/Telegram/StickerSet.php new file mode 100644 index 0000000..101b305 --- /dev/null +++ b/src/TgBotLib/Objects/Telegram/StickerSet.php @@ -0,0 +1,157 @@ +name; + } + + /** + * Sticker set title + * + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * Type of stickers in the set, currently one of “regular”, “mask”, “custom_emoji” + * + * @return string + * @see StickerType + */ + public function getStickerType(): string + { + return $this->sticker_type; + } + + /** + * True, if the sticker set contains animated stickers + * + * @return bool + * @link https://telegram.org/blog/animated-stickers + */ + public function isIsAnimated(): bool + { + return $this->is_animated; + } + + /** + * True, if the sticker set contains video stickers + * + * @link https://telegram.org/blog/video-stickers-better-reactions + * @return bool + */ + public function isIsVideo(): bool + { + return $this->is_video; + } + + /** + * List of all set stickers + * + * @return Sticker[] + */ + public function getStickers(): array + { + return $this->stickers; + } + + /** + * Optional. Sticker set thumbnail in the .WEBP, .TGS, or .WEBM format + * + * @return PhotoSize|null + */ + public function getThumbnail(): ?PhotoSize + { + return $this->thumbnail; + } + + /** + * @inheritDoc + */ + public function toArray(): array + { + return [ + 'name' => $this->name, + 'title' => $this->title, + 'sticker_type' => $this->sticker_type, + 'is_animated' => $this->is_animated, + 'is_video' => $this->is_video, + 'stickers' => array_map(function (Sticker $sticker) { + return $sticker->toArray(); + }, $this->stickers), + 'thumbnail' => ($this->thumbnail instanceof PhotoSize) ? $this->thumbnail->toArray() : null, + ]; + } + + /** + * @inheritDoc + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $object = new self(); + + $object->name = $data['name']; + $object->title = $data['title']; + $object->sticker_type = $data['sticker_type']; + $object->is_animated = $data['is_animated']; + $object->is_video = $data['is_video']; + $object->stickers = array_map(function (array $sticker) { + return Sticker::fromArray($sticker); + }, $data['stickers']); + $object->thumbnail = ($data['thumbnail'] !== null) ? PhotoSize::fromArray($data['thumbnail']) : null; + + return $object; + } + } \ No newline at end of file