Browse Source

Set attributes of StickerPack as Optional

pull/7494/head
Sebastian Law 3 years ago
committed by GitHub
parent
commit
3c6281ce33
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      discord/sticker.py
  2. 6
      discord/types/sticker.py

16
discord/sticker.py

@ -28,7 +28,7 @@ import unicodedata
from .mixins import Hashable
from .asset import Asset, AssetMixin
from .utils import cached_slot_property, find, snowflake_time, get, MISSING
from .utils import cached_slot_property, find, snowflake_time, get, MISSING, _get_as_snowflake
from .errors import InvalidData
from .enums import StickerType, StickerFormatType, try_enum
@ -87,9 +87,9 @@ class StickerPack(Hashable):
The stickers of this sticker pack.
sku_id: :class:`int`
The SKU ID of the sticker pack.
cover_sticker_id: :class:`int`
cover_sticker_id: Optional[:class:`int`]
The ID of the sticker used for the cover of the sticker pack.
cover_sticker: :class:`StandardSticker`
cover_sticker: Optional[:class:`StandardSticker`]
The sticker used for the cover of the sticker pack.
"""
@ -115,15 +115,15 @@ class StickerPack(Hashable):
self.stickers: List[StandardSticker] = [StandardSticker(state=self._state, data=sticker) for sticker in stickers]
self.name: str = data['name']
self.sku_id: int = int(data['sku_id'])
self.cover_sticker_id: int = int(data['cover_sticker_id'])
self.cover_sticker: StandardSticker = get(self.stickers, id=self.cover_sticker_id) # type: ignore
self.cover_sticker_id: Optional[int] = _get_as_snowflake(data, 'cover_sticker_id')
self.cover_sticker: Optional[StandardSticker] = get(self.stickers, id=self.cover_sticker_id)
self.description: str = data['description']
self._banner: int = int(data['banner_asset_id'])
self._banner: Optional[int] = _get_as_snowflake(data, 'banner_asset_id')
@property
def banner(self) -> Asset:
def banner(self) -> Optional[Asset]:
""":class:`Asset`: The banner asset of the sticker pack."""
return Asset._from_sticker_banner(self._state, self._banner)
return self._banner and Asset._from_sticker_banner(self._state, self._banner)
def __repr__(self) -> str:
return f'<StickerPack id={self.id} name={self.name!r} description={self.description!r}>'

6
discord/types/sticker.py

@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations
from typing import List, Literal, TypedDict, Union
from typing import List, Literal, TypedDict, Union, Optional
from .snowflake import Snowflake
from .user import User
@ -69,9 +69,9 @@ class StickerPack(TypedDict):
stickers: List[StandardSticker]
name: str
sku_id: Snowflake
cover_sticker_id: Snowflake
cover_sticker_id: Optional[Snowflake]
description: str
banner_asset_id: Snowflake
banner_asset_id: Optional[Snowflake]
class _CreateGuildStickerOptional(TypedDict, total=False):

Loading…
Cancel
Save