23
23
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
24
DEALINGS IN THE SOFTWARE.
25
25
"""
26
- from typing import Optional , List , Tuple , TYPE_CHECKING , Union , Dict
26
+ from __future__ import annotations
27
27
28
- from multidict import MultiDict
28
+ from typing import (
29
+ Optional ,
30
+ List ,
31
+ Tuple ,
32
+ TYPE_CHECKING ,
33
+ Union
34
+ )
29
35
30
36
from .mixins import Hashable
31
37
from .asset import Asset
32
38
from .utils import snowflake_time , get as utils_get
33
39
from .enums import StickerType , try_enum
34
40
35
41
if TYPE_CHECKING :
42
+ from datetime import datetime
43
+
44
+ from .guild import Guild
45
+ from .user import User
36
46
from .state import ConnectionState
37
47
38
48
39
49
class StickerPack (Hashable ):
40
- """Represents a Sticker Pack object.
50
+ """Represents a pack of build-in stickers
41
51
42
52
Attributes
43
53
----------
@@ -53,9 +63,8 @@ class StickerPack(Hashable):
53
63
The id of the sticker pack's banner image.
54
64
cover_sticker_id: Optional[:class:`int`]
55
65
The id of a sticker in the pack which is shown in the client as the pack's icon.
56
-
57
66
"""
58
- def __init__ (self , state : ' ConnectionState' , data ):
67
+ def __init__ (self , state : ConnectionState , data ) -> None :
59
68
self ._state = state
60
69
self .id = int (data ['id' ])
61
70
self .name : str = data ['name' ]
@@ -66,21 +75,56 @@ def __init__(self, state: 'ConnectionState', data):
66
75
self .__stickers : Tuple [Sticker ] = tuple (map (lambda d : state .store_sticker (d , self ), data ['stickers' ]))
67
76
68
77
@property
69
- def stickers (self ) -> Tuple ['Sticker' ]:
78
+ def stickers (self ) -> Tuple [Sticker ]:
79
+ "Tuple[:class:`Sticker`]: The stickers of the pack"
70
80
return self .__stickers
71
81
72
82
@stickers .setter
73
83
def stickers (self , value ):
74
84
raise TypeError ('Sticker Packs are immutable.' )
75
85
76
86
@property
77
- def banner_url (self ):
87
+ def banner_url (self ) -> Asset :
88
+ """Returns an :class:`Asset` for the sticker pack's banner.
89
+
90
+ Returns
91
+ -------
92
+ :class:`Asset`
93
+ The resulting CDN asset.
94
+ """
78
95
return self .banner_url_as ()
79
96
80
- def banner_url_as (self , format : str = 'png' , size = 1024 ):
97
+ def banner_url_as (self , format : str = 'png' , size = 1024 ) -> Asset :
98
+ """Returns an :class:`Asset` for the sticker pack's banner.
99
+
100
+ The size must be a power of 2 between 16 and 4096.
101
+
102
+ Returns
103
+ -------
104
+ :class:`Asset`
105
+ The resulting CDN asset.
106
+ """
81
107
return Asset ._from_sticker_pack (self ._state , self , format = format , size = size )
82
108
83
- def get_sticker (self , id : int ) -> Optional ['Sticker' ]:
109
+ @property
110
+ def cover_sticker (self ) -> Sticker :
111
+ """:class:`Sticker`: Returns the sticker in the pack which is shown in the client as the pack's icon."""
112
+ return self .get_sticker (self .cover_sticker_id )
113
+
114
+ def get_sticker (self , id : int ) -> Optional [Sticker ]:
115
+ """
116
+ Returns a sticker of the pack with the given id or :obj:`None` if not found.
117
+
118
+ Parameters
119
+ -----------
120
+ id: :class:`int`
121
+ The id of the sticker to get
122
+
123
+ Returns
124
+ --------
125
+ Optional[:class:`Sticker`]
126
+ The sticker or ``None`` if not found.
127
+ """
84
128
return utils_get (self .stickers , id = id )
85
129
86
130
@@ -117,18 +161,21 @@ class Sticker(Hashable):
117
161
The format for the sticker's image.
118
162
tags: List[:class:`str`]
119
163
A list of tags for the sticker.
164
+ pack: Optional[:class:`StickerPack`]
165
+ The pack the sticker belongs to. Could be :obj:`None` even if :attr:`Sticker.pack_id` is present.
166
+ sort_value: :class:`int`
167
+ The sticker's sort order within its :attr:`Sticker.pack`.
120
168
"""
121
- __slots__ = ('_state' , 'id' , 'name' , 'description' , 'pack_id' , 'format' , 'tags' , 'sort_value' , 'available' , 'pack' )
169
+ __slots__ = ('_state' , 'id' , 'name' , 'description' , 'pack_id' , 'format' , 'tags' , 'sort_value' , 'pack' )
122
170
123
- def __init__ (self , * , state , data , pack : Optional [StickerPack ] = None ):
171
+ def __init__ (self , * , state , data , pack : Optional [StickerPack ] = None ) -> None :
124
172
self ._state = state
125
173
self .id = int (data ['id' ])
126
174
self .name : str = data ['name' ]
127
175
self .description : str = data .get ('description' , None )
128
176
self .pack_id : int = int (data .get ('pack_id' , 0 ))
129
177
self .format : StickerType = try_enum (StickerType , data ['format_type' ])
130
178
self .sort_value = data .get ('sort_value' , 0 )
131
- self .available = data .get ('available' , True )
132
179
try :
133
180
self .tags = [tag .strip () for tag in data ['tags' ].split (',' )]
134
181
except KeyError :
@@ -142,12 +189,12 @@ def __str__(self):
142
189
return self .name
143
190
144
191
@property
145
- def created_at (self ):
192
+ def created_at (self ) -> datetime :
146
193
""":class:`datetime.datetime`: Returns the sticker's creation time in UTC as a naive datetime."""
147
194
return snowflake_time (self .id )
148
195
149
196
@property
150
- def image_url (self ):
197
+ def image_url (self ) -> Asset :
151
198
"""Returns an :class:`Asset` for the sticker's image.
152
199
153
200
.. note::
@@ -160,7 +207,7 @@ def image_url(self):
160
207
"""
161
208
return self .image_url_as ()
162
209
163
- def image_url_as (self ):
210
+ def image_url_as (self ) -> Asset :
164
211
"""Optionally returns an :class:`Asset` for the sticker's image.
165
212
166
213
The size must be a power of 2 between 16 and 4096.
@@ -180,27 +227,52 @@ def image_url_as(self):
180
227
181
228
182
229
class GuildSticker (Sticker ):
183
- """Represents a "custom" Sticker in a guild"""
184
- def __init__ (self , * , state : 'ConnectionState' , data ):
230
+ """
231
+ Represents a "custom" sticker in a guild
232
+
233
+ Attributes
234
+ ----------
235
+ name: :class:`str`
236
+ The sticker's name.
237
+ id: :class:`int`
238
+ The id of the sticker.
239
+ description: :class:`str`
240
+ The description of the sticker.
241
+ format: :class:`StickerType`
242
+ The format for the sticker's image.
243
+ tags: List[:class:`str`]
244
+ A list of tags for the sticker.
245
+ guild_id: :class:`int`
246
+ The id of the guild wich this sticker belongs to.
247
+ available: :class:`bool`
248
+ Whether this guild sticker can be used, may be :obj:`False` due to loss of Server Boosts
249
+ user: :class:`User`
250
+ The user that uploaded the guild sticker
251
+ """
252
+ __slots__ = ('_state' , 'id' , 'name' , 'description' , 'format' , 'tags' , 'available' , 'guild_id' , 'user' )
253
+
254
+ def __init__ (self , * , state : ConnectionState , data ) -> None :
185
255
super ().__init__ (state = state , data = data )
186
- self .guild_id = int (data ['guild_id' ])
256
+ self .guild_id : int = int (data ['guild_id' ])
257
+ self .available = data .get ('available' , True )
187
258
try :
188
259
user = data ['user' ]
189
260
except KeyError :
190
- self .user = None
261
+ self .user : Optional [ User ] = None
191
262
else :
192
- self .user = state .store_user (user )
263
+ self .user : Optional [ User ] = state .store_user (user )
193
264
194
265
@property
195
- def guild (self ):
266
+ def guild (self ) -> Guild :
267
+ """:class:`Guild`: The guild the sticker belongs to"""
196
268
return self ._state ._get_guild (self .guild_id )
197
269
198
270
def _update (self , data ):
199
271
for k , v in data .items ():
200
272
setattr (self , k , v )
201
273
return self
202
274
203
- async def edit (self , * , reason : Optional [str ] = None , ** fields ):
275
+ async def edit (self , * , reason : Optional [str ] = None , ** fields ) -> GuildSticker :
204
276
"""|coro|
205
277
206
278
Modify the sticker.
@@ -263,15 +335,15 @@ async def edit(self, *, reason: Optional[str] = None, **fields):
263
335
data = await self ._state .http .edit_guild_sticker (guild_id = self .guild_id , sticker_id = self .id , data = fields , reason = reason )
264
336
return self ._update (data )
265
337
266
- async def delete (self , * , reason : Optional [str ]):
338
+ async def delete (self , * , reason : Optional [str ]) -> GuildSticker :
267
339
"""|coro|
268
340
269
341
Delete the sticker.
270
342
271
343
Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
272
344
273
345
Parameters
274
- ----------
346
+ -----------
275
347
reason: Optional[:class:`str`]
276
348
The reason for deleting the sticker, shows up in the audit-log.
277
349
@@ -282,8 +354,8 @@ async def delete(self, *, reason: Optional[str]):
282
354
discord.HTTPException:
283
355
Deleting the sticker failed.
284
356
285
- Return
286
- ------
357
+ Returns
358
+ -------
287
359
discord.GuildSticker:
288
360
The sticker that was deleted.
289
361
"""
0 commit comments