-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathSticker.php
210 lines (170 loc) · 6.28 KB
/
Sticker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/*
* DiscordBot, PocketMine-MP Plugin.
*
* Licensed under the Open Software License version 3.0 (OSL-3.0)
* Copyright (C) 2020-present JaxkDev
*
* Discord :: JaxkDev
* Email :: [email protected]
*/
namespace JaxkDev\DiscordBot\Models;
use JaxkDev\DiscordBot\Communication\BinarySerializable;
use JaxkDev\DiscordBot\Communication\BinaryStream;
use JaxkDev\DiscordBot\Plugin\Utils;
/**
* Partial sticker object.
*
* @implements BinarySerializable<Sticker>
* @link https://discord.com/developers/docs/resources/sticker#sticker-object-sticker-structure
*/
final class Sticker implements BinarySerializable{
/** id of the sticker */
private string $id;
/** for standard stickers, id of the pack the sticker is from */
private ?string $pack_id;
/** name of the sticker */
private string $name;
/** description of the sticker */
private ?string $description;
/**
* autocomplete/suggestion tags for the sticker (max 200 characters)
* Comma seperated list of keywords. (eg. "hello, hi, hey")
*/
private ?string $tags;
/** type of sticker */
private StickerType $type;
/** type of sticker format */
private StickerFormatType $format_type;
/** whether this guild sticker can be used, may be false due to loss of Server Boosts */
private ?bool $available;
/** id of the guild that owns this sticker */
private ?string $guild_id;
/** the user that uploaded the guild sticker */
private ?string $user_id;
/** a sticker's sort order within a pack */
private ?int $sort_value;
public function __construct(string $id, ?string $pack_id, string $name, ?string $description, ?string $tags,
StickerType $type, StickerFormatType $format_type, ?bool $available, ?string $guild_id,
?string $user_id, ?int $sort_value){
$this->setId($id);
$this->setPackId($pack_id);
$this->setName($name);
$this->setDescription($description);
$this->setTags($tags);
$this->setType($type);
$this->setFormatType($format_type);
$this->setAvailable($available);
$this->setGuildId($guild_id);
$this->setUserId($user_id);
$this->setSortValue($sort_value);
}
public function getId(): string{
return $this->id;
}
public function setId(string $id): void{
if(!Utils::validDiscordSnowflake($id)){
throw new \AssertionError("Sticker ID '$id' is invalid.");
}
$this->id = $id;
}
public function getPackId(): ?string{
return $this->pack_id;
}
public function setPackId(?string $pack_id): void{
if($pack_id !== null && !Utils::validDiscordSnowflake($pack_id)){
throw new \AssertionError("Sticker pack ID '$pack_id' is invalid.");
}
$this->pack_id = $pack_id;
}
public function getName(): string{
return $this->name;
}
public function setName(string $name): void{
$this->name = $name;
}
public function getDescription(): ?string{
return $this->description;
}
public function setDescription(?string $description): void{
$this->description = $description;
}
public function getTags(): ?string{
return $this->tags;
}
public function setTags(?string $tags): void{
$this->tags = $tags;
}
public function getType(): StickerType{
return $this->type;
}
public function setType(StickerType $type): void{
$this->type = $type;
}
public function getFormatType(): StickerFormatType{
return $this->format_type;
}
public function setFormatType(StickerFormatType $format_type): void{
$this->format_type = $format_type;
}
public function getAvailable(): ?bool{
return $this->available;
}
public function setAvailable(?bool $available): void{
$this->available = $available;
}
public function getGuildId(): ?string{
return $this->guild_id;
}
public function setGuildId(?string $guild_id): void{
if($guild_id !== null && !Utils::validDiscordSnowflake($guild_id)){
throw new \AssertionError("Sticker guild ID '$guild_id' is invalid.");
}
$this->guild_id = $guild_id;
}
public function getUserId(): ?string{
return $this->user_id;
}
public function setUserId(?string $user_id): void{
if($user_id !== null && !Utils::validDiscordSnowflake($user_id)){
throw new \AssertionError("Sticker user ID '$user_id' is invalid.");
}
$this->user_id = $user_id;
}
public function getSortValue(): ?int{
return $this->sort_value;
}
public function setSortValue(?int $sort_value): void{
$this->sort_value = $sort_value;
}
public function binarySerialize(): BinaryStream{
$stream = new BinaryStream();
$stream->putString($this->id);
$stream->putNullableString($this->pack_id);
$stream->putString($this->name);
$stream->putNullableString($this->description);
$stream->putNullableString($this->tags);
$stream->putByte($this->type->value);
$stream->putByte($this->format_type->value);
$stream->putNullableBool($this->available);
$stream->putNullableString($this->guild_id);
$stream->putNullableString($this->user_id);
$stream->putNullableInt($this->sort_value);
return $stream;
}
public static function fromBinary(BinaryStream $stream): self{
return new self(
$stream->getString(), // id
$stream->getNullableString(), // pack_id
$stream->getString(), // name
$stream->getNullableString(), // description
$stream->getNullableString(), // tags
StickerType::from($stream->getByte()), // type
StickerFormatType::from($stream->getByte()),// format_type
$stream->getNullableBool(), // available
$stream->getNullableString(), // guild_id
$stream->getNullableString(), // user_id
$stream->getNullableInt() // sort_value
);
}
}