Moved Stickers
This commit is contained in:
parent
0b8603ec75
commit
6c9af0b1d8
7 changed files with 10 additions and 4 deletions
105
src/TgBotLib/Objects/Stickers/MaskPosition.php
Normal file
105
src/TgBotLib/Objects/Stickers/MaskPosition.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace TgBotLib\Objects\Stickers;
|
||||
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
|
||||
class MaskPosition implements ObjectTypeInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $point;
|
||||
|
||||
/**
|
||||
* @var float|int
|
||||
*/
|
||||
private $x_shift;
|
||||
|
||||
/**
|
||||
* @var float|int
|
||||
*/
|
||||
private $y_shift;
|
||||
|
||||
/**
|
||||
* @var float|int
|
||||
*/
|
||||
private $scale;
|
||||
|
||||
/**
|
||||
* The part of the face relative to which the mask should be placed. One of “forehead”, “eyes”, “mouth”, or
|
||||
* “chin”.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPoint(): string
|
||||
{
|
||||
return $this->point;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. For example,
|
||||
* choosing -1.0 will place mask just to the left of the default mask position.
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public function getXShift(): float|int
|
||||
{
|
||||
return $this->x_shift;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. For example,
|
||||
* 1.0 will place the mask just below the default mask position.
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public function getYShift(): float|int
|
||||
{
|
||||
return $this->y_shift;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mask scaling coefficient. For example, 2.0 means double size.
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public function getScale(): float|int
|
||||
{
|
||||
return $this->scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'point' => $this->point,
|
||||
'x_shift' => $this->x_shift,
|
||||
'y_shift' => $this->y_shift,
|
||||
'scale' => $this->scale,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs object from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return MaskPosition
|
||||
*/
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
$object = new self();
|
||||
|
||||
$object->point = $data['point'] ?? null;
|
||||
$object->x_shift = $data['x_shift'] ?? null;
|
||||
$object->y_shift = $data['y_shift'] ?? null;
|
||||
$object->scale = $data['scale'] ?? null;
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
296
src/TgBotLib/Objects/Stickers/Sticker.php
Normal file
296
src/TgBotLib/Objects/Stickers/Sticker.php
Normal file
|
@ -0,0 +1,296 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace TgBotLib\Objects\Stickers;
|
||||
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
use TgBotLib\Objects\File;
|
||||
use TgBotLib\Objects\PhotoSize;
|
||||
|
||||
class Sticker implements ObjectTypeInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $file_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $file_unique_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $width;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $height;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $is_animated;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $is_video;
|
||||
|
||||
/**
|
||||
* @var PhotoSize|null
|
||||
*/
|
||||
private $thumbnail;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $emoji;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $set_name;
|
||||
|
||||
/**
|
||||
* @var File|null
|
||||
*/
|
||||
private $premium_animation;
|
||||
|
||||
/**
|
||||
* @var MaskPosition|null
|
||||
*/
|
||||
private $mask_position;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $custom_emoji_id;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $needs_repainting;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $file_size;
|
||||
|
||||
/**
|
||||
* Identifier for this file, which can be used to download or reuse the file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileId(): string
|
||||
{
|
||||
return $this->file_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unique identifier for this file, which is supposed to be the same over time and for different bots.
|
||||
* Can't be used to download or reuse the file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileUniqueId(): string
|
||||
{
|
||||
return $this->file_unique_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of the sticker, currently one of “regular”, “mask”, “custom_emoji”. The type of the sticker is
|
||||
* independent of its format, which is determined by the fields is_animated and is_video.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sticker width
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getWidth(): int
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sticker height
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHeight(): int
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
/**
|
||||
* True, if the sticker is animated
|
||||
*
|
||||
* @see https://telegram.org/blog/animated-stickers
|
||||
* @return bool
|
||||
*/
|
||||
public function isIsAnimated(): bool
|
||||
{
|
||||
return $this->is_animated;
|
||||
}
|
||||
|
||||
/**
|
||||
* True, if the sticker is a video sticker
|
||||
*
|
||||
* @see https://telegram.org/blog/video-stickers-better-reactions
|
||||
* @return bool
|
||||
*/
|
||||
public function isIsVideo(): bool
|
||||
{
|
||||
return $this->is_video;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Sticker thumbnail in the .WEBP or .JPG format
|
||||
*
|
||||
* @return PhotoSize|null
|
||||
*/
|
||||
public function getThumbnail(): ?PhotoSize
|
||||
{
|
||||
return $this->thumbnail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Emoji associated with the sticker
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getEmoji(): ?string
|
||||
{
|
||||
return $this->emoji;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Name of the sticker set to which the sticker belongs
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSetName(): ?string
|
||||
{
|
||||
return $this->set_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. For premium regular stickers, premium animation for the sticker
|
||||
*
|
||||
* @return File|null
|
||||
*/
|
||||
public function getPremiumAnimation(): ?File
|
||||
{
|
||||
return $this->premium_animation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. For mask stickers, the position where the mask should be placed
|
||||
*
|
||||
* @return MaskPosition|null
|
||||
*/
|
||||
public function getMaskPosition(): ?MaskPosition
|
||||
{
|
||||
return $this->mask_position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. For custom emoji stickers, unique identifier of the custom emoji
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCustomEmojiId(): ?string
|
||||
{
|
||||
return $this->custom_emoji_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. True, if the sticker must be repainted to a text color in messages, the color of the Telegram
|
||||
* Premium badge in emoji status, white color on chat photos, or another appropriate color in other places
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function needsRepainting(): bool
|
||||
{
|
||||
return $this->needs_repainting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. File size in bytes
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getFileSize(): ?int
|
||||
{
|
||||
return $this->file_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'file_id' => $this->file_id,
|
||||
'file_unique_id' => $this->file_unique_id,
|
||||
'type' => $this->type,
|
||||
'width' => $this->width,
|
||||
'height' => $this->height,
|
||||
'is_animated' => $this->is_animated,
|
||||
'is_video' => $this->is_video,
|
||||
'thumbnail' => ($this->thumbnail instanceof ObjectTypeInterface) ? $this->thumbnail->toArray() : $this->thumbnail,
|
||||
'emoji' => $this->emoji,
|
||||
'set_name' => $this->set_name,
|
||||
'premium_animation' => ($this->premium_animation instanceof ObjectTypeInterface) ? $this->premium_animation->toArray() : $this->premium_animation,
|
||||
'mask_position' => ($this->mask_position instanceof ObjectTypeInterface) ? $this->mask_position->toArray() : $this->mask_position,
|
||||
'custom_emoji_id' => $this->custom_emoji_id,
|
||||
'needs_repainting' => $this->needs_repainting,
|
||||
'file_size' => $this->file_size,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs object from an array representation.
|
||||
*
|
||||
* @param array $data
|
||||
* @return Sticker
|
||||
*/
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
$object = new static();
|
||||
|
||||
$object->file_id = $data['file_id'];
|
||||
$object->file_unique_id = $data['file_unique_id'];
|
||||
$object->type = $data['type'];
|
||||
$object->width = $data['width'];
|
||||
$object->height = $data['height'];
|
||||
$object->is_animated = $data['is_animated'];
|
||||
$object->is_video = $data['is_video'];
|
||||
$object->thumbnail = isset($data['thumbnail']) ? PhotoSize::fromArray($data['thumbnail']) : null;
|
||||
$object->emoji = $data['emoji'] ?? null;
|
||||
$object->set_name = $data['set_name'] ?? null;
|
||||
$object->premium_animation = isset($data['premium_animation']) ? File::fromArray($data['premium_animation']) : null;
|
||||
$object->mask_position = isset($data['mask_position']) ? MaskPosition::fromArray($data['mask_position']) : null;
|
||||
$object->custom_emoji_id = $data['custom_emoji_id'] ?? null;
|
||||
$object->needs_repainting = $data['needs_repainting'] ?? false;
|
||||
$object->file_size = $data['file_size'] ?? null;
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
157
src/TgBotLib/Objects/Stickers/StickerSet.php
Normal file
157
src/TgBotLib/Objects/Stickers/StickerSet.php
Normal file
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace TgBotLib\Objects\Stickers;
|
||||
|
||||
use TgBotLib\Enums\Types\StickerType;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
use TgBotLib\Objects\PhotoSize;
|
||||
|
||||
class StickerSet implements ObjectTypeInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sticker_type;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $is_animated;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $is_video;
|
||||
|
||||
/**
|
||||
* @var Sticker[]
|
||||
*/
|
||||
private $stickers;
|
||||
|
||||
/**
|
||||
* @var PhotoSize|null
|
||||
*/
|
||||
private $thumbnail;
|
||||
|
||||
/**
|
||||
* Sticker set name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue