-
Notifications
You must be signed in to change notification settings - Fork 145
feat(flags): add new flags to Embed and update Attachment flags #1283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
e423ff4
cad882c
5ec2135
b56f99c
46fc41b
9ae0716
9f61729
b00e4d4
56c1ff9
19421ce
84cb53a
0ba9d50
cb62db1
8c08dc0
9eaba41
4c05130
9ee20e6
2b233be
0ba596f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add :attr:`Embed.flags`, ``Embed.image.flags``, ``Embed.thumbnail.flags``, :class:`EmbedFlags`, :class:`EmbedMediaFlags` and update the :class:`AttachmentFlags`. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| from . import utils | ||
| from .colour import Colour | ||
| from .file import File | ||
| from .flags import EmbedFlags, EmbedMediaFlags | ||
| from .utils import MISSING, classproperty, warn_deprecated | ||
|
|
||
| __all__ = ("Embed",) | ||
|
|
@@ -89,6 +90,7 @@ class _EmbedMediaProxy(Sized, Protocol): | |
| proxy_url: Optional[str] | ||
| height: Optional[int] | ||
| width: Optional[int] | ||
| flags: Optional[EmbedMediaFlags] | ||
|
|
||
| class _EmbedVideoProxy(Sized, Protocol): | ||
| url: Optional[str] | ||
|
|
@@ -182,6 +184,7 @@ class Embed: | |
| "_fields", | ||
| "description", | ||
| "_files", | ||
| "_flags", | ||
| ) | ||
|
|
||
| _default_colour: ClassVar[Optional[Colour]] = None | ||
|
|
@@ -220,6 +223,7 @@ def __init__( | |
| self._image: Optional[EmbedImagePayload] = None | ||
| self._footer: Optional[EmbedFooterPayload] = None | ||
| self._fields: Optional[List[EmbedFieldPayload]] = None | ||
| self._flags: int = 0 | ||
|
|
||
| self._files: Dict[_FileKey, File] = {} | ||
|
|
||
|
|
@@ -267,12 +271,20 @@ def from_dict(cls, data: EmbedData) -> Self: | |
| self.timestamp = utils.parse_time(data.get("timestamp")) | ||
|
|
||
| self._thumbnail = data.get("thumbnail") | ||
| if self._thumbnail and (thumbnail_flags := self._thumbnail.get("flags")): | ||
| self._thumbnail["flags"] = EmbedMediaFlags._from_value(thumbnail_flags) # type: ignore | ||
|
|
||
| self._video = data.get("video") | ||
| self._provider = data.get("provider") | ||
| self._author = data.get("author") | ||
|
|
||
| self._image = data.get("image") | ||
| if self._image and (image_flags := self._image.get("flags")): | ||
| self._image["flags"] = EmbedMediaFlags._from_value(image_flags) # type: ignore | ||
|
|
||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like how this is done but I don't see much alternatives
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than save it here, we could make the flags when we access the image or thumbnail, no?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also no longer seems to be respected in serialisation.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What do you mean? It's not consistent with the lib?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
that was my idea as well. It's still a bit awkward, but a separate |
||
| self._footer = data.get("footer") | ||
| self._fields = data.get("fields") | ||
| self._flags = data.get("flags", 0) | ||
|
|
||
| return self | ||
|
|
||
|
|
@@ -371,6 +383,14 @@ def timestamp(self, value: Optional[datetime.datetime]) -> None: | |
| f"Expected datetime.datetime or None received {type(value).__name__} instead" | ||
| ) | ||
|
|
||
| @property | ||
| def flags(self) -> Optional[EmbedFlags]: | ||
| """Optional[:class:`EmbedFlags`]: Returns the embed's flags. | ||
|
|
||
| .. versionadded:: 2.11 | ||
| """ | ||
| return EmbedFlags._from_value(self._flags) | ||
|
onerandomusername marked this conversation as resolved.
|
||
|
|
||
| @property | ||
| def footer(self) -> _EmbedFooterProxy: | ||
| """Returns an ``EmbedProxy`` denoting the footer contents. | ||
|
|
@@ -455,6 +475,11 @@ def image(self) -> _EmbedMediaProxy: | |
| - ``proxy_url`` | ||
| - ``width`` | ||
| - ``height`` | ||
| - ``flags`` | ||
|
|
||
| .. versionchanged:: 2.11 | ||
|
Snipy7374 marked this conversation as resolved.
Outdated
|
||
|
|
||
| Added the ``flags`` attribute. | ||
|
|
||
| If an attribute is not set, it will be ``None``. | ||
| """ | ||
|
|
@@ -508,6 +533,11 @@ def thumbnail(self) -> _EmbedMediaProxy: | |
| - ``proxy_url`` | ||
| - ``width`` | ||
| - ``height`` | ||
| - ``flags`` | ||
|
|
||
| .. versionchanged:: 2.11 | ||
|
|
||
| Added the ``flags`` attribute. | ||
|
|
||
| If an attribute is not set, it will be ``None``. | ||
| """ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.