Repository navigation
feat(flags): implement content scan flags #1629
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 3 commits
2874bf4
66f6888
ca64c38
1556e55
e7a32e0
7810653
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 :meth:`~disnake.AttachmentFlags.contains_explicit_content`, :meth:`~disnake.AttachmentFlags.contains_gore_content`, :meth:`~disnake.AttachmentFlags.contains_self_harm_content`, :class:`~disnake.UnfurledScanMetadataFlags`, :attr:`.UnfurledMediaItem.content_scan_metadata` and :class:`.UnfurledScanMetadata`. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ | |
| TextInputStyle, | ||
| try_enum, | ||
| ) | ||
| from .flags import UnfurledMediaItemFlags | ||
| from .flags import UnfurledMediaItemFlags, UnfurledScanMetadataFlags | ||
| from .partial_emoji import PartialEmoji, _EmojiTag | ||
| from .utils import MISSING, _get_as_snowflake, assert_never, get_slots | ||
|
|
||
|
|
@@ -69,6 +69,7 @@ | |
| TextInput as TextInputPayload, | ||
| ThumbnailComponent as ThumbnailComponentPayload, | ||
| UnfurledMediaItem as UnfurledMediaItemPayload, | ||
| UnfurledScanMetadata as UnfurledScanMetadataPayload, | ||
| UserSelectMenu as UserSelectMenuPayload, | ||
| ) | ||
|
|
||
|
|
@@ -89,6 +90,7 @@ | |
| "Section", | ||
| "TextDisplay", | ||
| "UnfurledMediaItem", | ||
| "UnfurledScanMetadata", | ||
| "Thumbnail", | ||
| "MediaGallery", | ||
| "MediaGalleryItem", | ||
|
|
@@ -1144,6 +1146,10 @@ class UnfurledMediaItem: | |
| .. versionadded:: |vnext| | ||
| content_type: :class:`str` | :data:`None` | ||
| The `media type <https://en.wikipedia.org/wiki/Media_type>`_ of this media item. | ||
| content_scan_metadata: :class:`UnfurledScanMetadata` | :data:`None` | ||
| The content scan metadata for this media item, if any. | ||
|
|
||
| .. versionadded:: |vnext| | ||
| attachment_id: :class:`int` | :data:`None` | ||
| The ID of the uploaded attachment. Only present if the media item was | ||
| uploaded as an attachment. | ||
|
|
@@ -1159,6 +1165,7 @@ class UnfurledMediaItem: | |
| "_flags", | ||
| "content_type", | ||
| "attachment_id", | ||
| "content_scan_metadata", | ||
| ) | ||
|
|
||
| # generally, users should also be able to pass a plain url where applicable instead of | ||
|
|
@@ -1172,6 +1179,7 @@ def __init__(self, url: str) -> None: | |
| self.placeholder_version: int | None = None | ||
| self._flags: int = 0 | ||
| self.content_type: str | None = None | ||
| self.content_scan_metadata: UnfurledScanMetadata | None = None | ||
| self.attachment_id: int | None = None | ||
|
|
||
| @classmethod | ||
|
|
@@ -1184,6 +1192,11 @@ def from_dict(cls, data: UnfurledMediaItemPayload) -> Self: | |
| self.placeholder_version = data.get("placeholder_version") | ||
| self._flags = data.get("flags", 0) | ||
| self.content_type = data.get("content_type") | ||
| self.content_scan_metadata = ( | ||
| UnfurledScanMetadata(metadata) | ||
| if (metadata := data.get("content_scan_metadata")) | ||
| else None | ||
| ) | ||
| self.attachment_id = _get_as_snowflake(data, "attachment_id") | ||
| return self | ||
|
|
||
|
|
@@ -1203,6 +1216,23 @@ def __repr__(self) -> str: | |
| return f"<UnfurledMediaItem url={self.url} content_type={self.content_type}>" | ||
|
|
||
|
|
||
| class UnfurledScanMetadata: | ||
|
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. Not really a fan of this naming, but then again,
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. With
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.
For now, yes, but this could potentially change in the future, we just kinda don't know :/ |
||
| """Represents the content scan metadata for an unfurled media item. | ||
|
|
||
| .. versionadded:: |vnext| | ||
| """ | ||
|
|
||
| __slots__: tuple[str, ...] = ("_flags",) | ||
|
|
||
| def __init__(self, data: UnfurledScanMetadataPayload) -> None: | ||
| self._flags: int = data.get("flags", 0) | ||
|
|
||
| @property | ||
| def flags(self) -> UnfurledScanMetadataFlags: | ||
| """:class:`UnfurledScanMetadataFlags`: The flags for this content scan metadata.""" | ||
| return UnfurledScanMetadataFlags._from_value(self._flags) | ||
|
|
||
|
|
||
| class Thumbnail(Component): | ||
| """Represents a thumbnail from the Discord Bot UI Kit (v2). | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.