feat(flags): add new flags to Embed and update Attachment flags - #1283
feat(flags): add new flags to Embed and update Attachment flags#1283Snipy7374 wants to merge 10 commits into
Conversation
| 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 | ||
|
|
There was a problem hiding this comment.
I don't like how this is done but I don't see much alternatives
There was a problem hiding this comment.
Rather than save it here, we could make the flags when we access the image or thumbnail, no?
There was a problem hiding this comment.
This also no longer seems to be respected in serialisation.
There was a problem hiding this comment.
This also no longer seems to be respected in serialisation.
What do you mean? It's not consistent with the lib?
There was a problem hiding this comment.
Rather than save it here, we could make the flags when we access the image or thumbnail, no?
that was my idea as well. It's still a bit awkward, but a separate EmbedProxy subclass that special-cases flags should do, and doesn't result in weird consistency issues with from_dict and to_dict.
Co-authored-by: Eneg <42005170+Enegg@users.noreply.github.com> Signed-off-by: arielle <me@arielle.codes>
|
@Snipy7374 would you please resolve conflicts and rebase? |
| @@ -0,0 +1 @@ | |||
| Add :attr:`Embed.flags`, ``Embed.image.flags``, ``Embed.thumbnail.flags``, :class:`EmbedFlags`, :class:`EmbedMediaFlags` and update the :class:`AttachmentFlags`. | |||
There was a problem hiding this comment.
Seems like this is missing the unfurled media item flags, which were added later in the API docs PR.
| inline: NotRequired[bool] | ||
|
|
||
|
|
||
| class EmbedThumbnail(TypedDict): |
There was a problem hiding this comment.
The API docs got rid of the image/thumbnail structure split, it would make sense to just add a EmbedThumbnail = EmbedImage alias here instead of updating the structures individually
| .. versionchanged:: |vnext| | ||
|
|
||
| Added the ``flags`` attribute. | ||
|
|
||
| If an attribute is not set, it will be :data:`None`. |
There was a problem hiding this comment.
| .. versionchanged:: |vnext| | |
| Added the ``flags`` attribute. | |
| If an attribute is not set, it will be :data:`None`. | |
| If an attribute is not set, it will be :data:`None`. | |
| .. versionchanged:: |vnext| | |
| Added the ``flags`` attribute. |
| .. versionchanged:: |vnext| | ||
|
|
||
| Added the ``flags`` attribute. | ||
|
|
||
| If an attribute is not set, it will be :data:`None`. |
There was a problem hiding this comment.
| .. versionchanged:: |vnext| | |
| Added the ``flags`` attribute. | |
| If an attribute is not set, it will be :data:`None`. | |
| If an attribute is not set, it will be :data:`None`. | |
| .. versionchanged:: |vnext| | |
| Added the ``flags`` attribute. |
|
|
||
| @flag_value | ||
| def is_clip(self): | ||
| """:class:`bool`: Returns ``True`` if the attachment is a clip. |
There was a problem hiding this comment.
| """:class:`bool`: Returns ``True`` if the attachment is a clip. | |
| """:class:`bool`: Returns ``True`` if the attachment is a clip from a stream. |
| return 1 << 3 | ||
|
|
||
| @flag_value | ||
| def contains_explicit_media(self): |
There was a problem hiding this comment.
This flag seems to have been removed from the docs again
| ) -> None: ... | ||
|
|
||
| @flag_value | ||
| def contains_explicit_media(self): |
There was a problem hiding this comment.
Same here, was removed from the docs
|
|
||
| @flag_value | ||
| def is_animated(self): | ||
| """:class:`bool`: Returns ``True`` if the embed media is animated.""" |
There was a problem hiding this comment.
| """:class:`bool`: Returns ``True`` if the embed media is animated.""" | |
| """:class:`bool`: Returns ``True`` if the embed image is animated.""" |
"media" is plural, at least in this context (apparently it can be singular when referring to mass media?). "embed medium" also sounds a bit weird, so "embed image" seems like a good compromise to me
| clip_participants: List[:class:`User`] | ||
| If this attachment is a clip returns a list of users who were in the stream. | ||
|
|
||
| .. versionadded:: |vnext| | ||
|
|
||
| clip_created_at: Optional[:class:`datetime.datetime`] | ||
| If this attachment is a clip returns the creation timestamp. | ||
|
|
||
| .. versionadded:: |vnext| |
There was a problem hiding this comment.
| clip_participants: List[:class:`User`] | |
| If this attachment is a clip returns a list of users who were in the stream. | |
| .. versionadded:: |vnext| | |
| clip_created_at: Optional[:class:`datetime.datetime`] | |
| If this attachment is a clip returns the creation timestamp. | |
| .. versionadded:: |vnext| | |
| clip_participants: :class:`list`\[:class:`User`] | |
| The list of users who were in the stream, if this attachment is a clip. | |
| .. versionadded:: |vnext| | |
| clip_created_at: :class:`datetime.datetime` | :data:`None` | |
| The creation timestamp, if this attachment is a clip. | |
| .. versionadded:: |vnext| |
| self.clip_participants: list[User] = [ | ||
| User(state=state, data=d) for d in data.get("clip_participants", []) | ||
| ] | ||
| self.clip_created_at: datetime.datetime | None = utils.parse_time( | ||
| data.get("clip_created_at") | ||
| ) |
There was a problem hiding this comment.
There are a few more non-flags-related additions in the API docs PR - I'd say this PR should either only add the new flags, or everything
Summary
Checklist
pdm lintpdm pyright