Added ChatBoostSource objects
This commit is contained in:
parent
3b02d5a5c2
commit
e8a6e7a6e1
6 changed files with 275 additions and 0 deletions
10
src/TgBotLib/Enums/Types/ChatBoostSourceType.php
Normal file
10
src/TgBotLib/Enums/Types/ChatBoostSourceType.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Enums\Types;
|
||||
|
||||
enum ChatBoostSourceType : string
|
||||
{
|
||||
case PREMIUM = 'premium';
|
||||
case GIFT_CODE = 'gift_code';
|
||||
case GIVEAWAY = 'giveaway';
|
||||
}
|
23
src/TgBotLib/Objects/ChatBoostRemoved.php
Normal file
23
src/TgBotLib/Objects/ChatBoostRemoved.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Objects;
|
||||
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
|
||||
class ChatBoostRemoved implements ObjectTypeInterface
|
||||
{
|
||||
private Chat $chat;
|
||||
private string $boost_id;
|
||||
private int $remove_date;
|
||||
private ChatBoostSource $source;
|
||||
|
||||
public function toArray(): ?array
|
||||
{
|
||||
// TODO: Implement toArray() method.
|
||||
}
|
||||
|
||||
public static function fromArray(?array $data): ?ChatBoostRemoved
|
||||
{
|
||||
// TODO: Implement fromArray() method.
|
||||
}
|
||||
}
|
49
src/TgBotLib/Objects/ChatBoostSource.php
Normal file
49
src/TgBotLib/Objects/ChatBoostSource.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Objects;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use TgBotLib\Enums\Types\ChatBoostSourceType;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
use TgBotLib\Objects\ChatBoostSource\ChatBoostSourceGiftCode;
|
||||
use TgBotLib\Objects\ChatBoostSource\ChatBoostSourceGiveaway;
|
||||
use TgBotLib\Objects\ChatBoostSource\ChatBoostSourcePremium;
|
||||
|
||||
abstract class ChatBoostSource implements ObjectTypeInterface
|
||||
{
|
||||
protected ChatBoostSourceType $source;
|
||||
|
||||
/**
|
||||
* Source of the boost
|
||||
*
|
||||
* @return ChatBoostSourceType
|
||||
*/
|
||||
public function getSource(): ChatBoostSourceType
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public abstract function toArray(): ?array;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(?array $data): ?ChatBoostSource
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return match (ChatBoostSourceType::tryFrom($data['source']))
|
||||
{
|
||||
ChatBoostSourceType::GIFT_CODE => ChatBoostSourceGiftCode::fromArray($data),
|
||||
ChatBoostSourceType::PREMIUM => ChatBoostSourcePremium::fromArray($data),
|
||||
ChatBoostSourceType::GIVEAWAY => ChatBoostSourceGiveaway::fromArray($data),
|
||||
default => throw new InvalidArgumentException('Unknown source type')
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Objects\ChatBoostSource;
|
||||
|
||||
use TgBotLib\Enums\Types\ChatBoostSourceType;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
use TgBotLib\Objects\ChatBoostSource;
|
||||
use TgBotLib\Objects\User;
|
||||
|
||||
class ChatBoostSourceGiftCode extends ChatBoostSource implements ObjectTypeInterface
|
||||
{
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* User that boosted the chat
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'source' => $this->source->value,
|
||||
'user' => $this->user->toArray()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(?array $data): ?ChatBoostSourceGiftCode
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->source = ChatBoostSourceType::PREMIUM;
|
||||
$object->user = User::fromArray($data['user']);
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Objects\ChatBoostSource;
|
||||
|
||||
use TgBotLib\Enums\Types\ChatBoostSourceType;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
use TgBotLib\Objects\ChatBoostSource;
|
||||
use TgBotLib\Objects\User;
|
||||
|
||||
class ChatBoostSourceGiveaway extends ChatBoostSource implements ObjectTypeInterface
|
||||
{
|
||||
private int $giveaway_message_id;
|
||||
private ?User $user;
|
||||
private ?int $prize_star_count;
|
||||
private bool $is_unclaimed;
|
||||
|
||||
/**
|
||||
* Identifier of a message in the chat with the giveaway; the message could have been deleted already.
|
||||
* May be 0 if the message isn't sent yet.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getGiveawayMessageId(): int
|
||||
{
|
||||
return $this->giveaway_message_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. User that won the prize in the giveaway if any; for Telegram Premium giveaways only
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. The number of Telegram Stars to be split between giveaway winners; for Telegram Star giveaways only
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getPrizeStarCount(): ?int
|
||||
{
|
||||
return $this->prize_star_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. True, if the giveaway was completed, but there was no user to win the prize
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isIsUnclaimed(): bool
|
||||
{
|
||||
return $this->is_unclaimed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toArray(): ?array
|
||||
{
|
||||
return [
|
||||
'source' => $this->source->value,
|
||||
'giveaway_message_id' => $this->giveaway_message_id,
|
||||
'user' => $this->user?->toArray(),
|
||||
'prize_star_count' => $this->prize_star_count,
|
||||
'is_unclaimed' => $this->is_unclaimed
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(?array $data): ?ChatBoostSourceGiveaway
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->source = ChatBoostSourceType::GIVEAWAY;
|
||||
$object->giveaway_message_id = $data['giveaway_message_id'];
|
||||
$object->user = User::fromArray($data['user']);
|
||||
$object->prize_star_count = $data['prize_star_count'];
|
||||
$object->is_unclaimed = $data['is_unclaimed'];
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Objects\ChatBoostSource;
|
||||
|
||||
use TgBotLib\Enums\Types\ChatBoostSourceType;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
use TgBotLib\Objects\ChatBoostSource;
|
||||
use TgBotLib\Objects\User;
|
||||
|
||||
class ChatBoostSourcePremium extends ChatBoostSource implements ObjectTypeInterface
|
||||
{
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* User that boosted the chat
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'source' => $this->source->value,
|
||||
'user' => $this->user?->toArray()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(?array $data): ?ChatBoostSourcePremium
|
||||
{
|
||||
if($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$object = new self();
|
||||
$object->source = ChatBoostSourceType::PREMIUM;
|
||||
$object->user = User::fromArray($data['user']);
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue