aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-05-29 00:19:11 -0400
committerRapptz <[email protected]>2021-05-29 00:19:11 -0400
commit7e1f8bf1b4733ce968240b244f9530204e97cf77 (patch)
treeb16b8c23e3760292b55bf3206d12b2cfd7da13ac
parent[commands] Add Command.extras (diff)
downloaddiscord.py-7e1f8bf1b4733ce968240b244f9530204e97cf77.tar.xz
discord.py-7e1f8bf1b4733ce968240b244f9530204e97cf77.zip
Typehint Sticker
-rw-r--r--discord/sticker.py36
1 files changed, 23 insertions, 13 deletions
diff --git a/discord/sticker.py b/discord/sticker.py
index c93ac763..19c41850 100644
--- a/discord/sticker.py
+++ b/discord/sticker.py
@@ -22,6 +22,9 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
+from __future__ import annotations
+from typing import TYPE_CHECKING, List, Optional
+
from .mixins import Hashable
from .asset import Asset
from .utils import snowflake_time
@@ -31,6 +34,12 @@ __all__ = (
'Sticker',
)
+if TYPE_CHECKING:
+ import datetime
+ from .state import ConnectionState
+ from .types.message import Sticker as StickerPayload
+
+
class Sticker(Hashable):
"""Represents a sticker.
@@ -65,35 +74,36 @@ class Sticker(Hashable):
tags: List[:class:`str`]
A list of tags for the sticker.
"""
+
__slots__ = ('_state', 'id', 'name', 'description', 'pack_id', 'format', '_image', 'tags')
- def __init__(self, *, state, data):
- self._state = state
- self.id = int(data['id'])
- self.name = data['name']
- self.description = data['description']
- self.pack_id = int(data['pack_id'])
- self.format = try_enum(StickerType, data['format_type'])
- self._image = data['asset']
+ def __init__(self, *, state: ConnectionState, data: StickerPayload):
+ self._state: ConnectionState = state
+ self.id: int = int(data['id'])
+ self.name: str = data['name']
+ self.description: str = data['description']
+ self.pack_id: int = int(data['pack_id'])
+ self.format: StickerType = try_enum(StickerType, data['format_type'])
+ self._image: str = data['asset']
try:
- self.tags = [tag.strip() for tag in data['tags'].split(',')]
+ self.tags: List[str] = [tag.strip() for tag in data['tags'].split(',')]
except KeyError:
self.tags = []
- def __repr__(self):
+ def __repr__(self) -> str:
return f'<{self.__class__.__name__} id={self.id} name={self.name!r}>'
- def __str__(self):
+ def __str__(self) -> str:
return self.name
@property
- def created_at(self):
+ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: Returns the sticker's creation time in UTC."""
return snowflake_time(self.id)
@property
- def image(self):
+ def image(self) -> Optional[Asset]:
"""Returns an :class:`Asset` for the sticker's image.
.. note::