Repository navigation
feat: Add spoiler channel flag and functions #3252
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 all commits
b1ded01
7b79faa
9d09881
65bfc90
f426f25
cb9f534
7aaad87
769cc08
19531ba
16309ed
68608ab
763c13f
f2cb6bb
9508a82
4f41083
7327338
57e3dd7
06167d2
c8f6f61
b56e022
2582634
ccca218
74dda97
0e64964
8fcaf91
414bd34
ca98dd2
7257401
3eeab68
bc6656f
e1be8da
9f74834
61df98c
b42aa42
a72f7e0
225cc81
937316a
553ba6c
9a071c5
eff44b5
626cc48
1f8afbe
250d4aa
767203a
8be7173
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -26,10 +26,12 @@ | |||||
| from __future__ import annotations | ||||||
|
|
||||||
| import datetime | ||||||
| import warnings | ||||||
| from collections.abc import Callable, Iterable, Mapping, Sequence | ||||||
| from typing import ( | ||||||
| TYPE_CHECKING, | ||||||
| Any, | ||||||
| Literal, | ||||||
| NamedTuple, | ||||||
| TypeVar, | ||||||
| overload, | ||||||
|
|
@@ -317,6 +319,17 @@ def is_nsfw(self) -> bool: | |||||
| """Checks if the channel is NSFW.""" | ||||||
| return self.nsfw | ||||||
|
|
||||||
| @property | ||||||
| def spoiler(self) -> bool: | ||||||
| """Checks if the channel is a spoiler channel. | ||||||
|
|
||||||
| .. note:: | ||||||
| This is an alias for :attr:`ChannelFlags.is_spoiler_channel`. | ||||||
|
|
||||||
| .. versionadded:: 2.9 | ||||||
| """ | ||||||
| return self.flags.is_spoiler_channel | ||||||
|
|
||||||
| @property | ||||||
| def last_message(self) -> Message | None: | ||||||
| """Fetches the last message from this channel in cache. | ||||||
|
|
@@ -809,6 +822,26 @@ async def edit( | |||||
| default_thread_slowmode_delay: int = ..., | ||||||
| type: ChannelType = ..., | ||||||
| overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., | ||||||
| spoiler: Literal[False] = ..., | ||||||
| ) -> TextChannel | None: ... | ||||||
|
|
||||||
| @overload | ||||||
| async def edit( | ||||||
| self, | ||||||
| *, | ||||||
| reason: str | None = ..., | ||||||
| name: str = ..., | ||||||
| topic: str = ..., | ||||||
| position: int = ..., | ||||||
| nsfw: Literal[False] = ..., | ||||||
| sync_permissions: bool = ..., | ||||||
| category: CategoryChannel | None = ..., | ||||||
| slowmode_delay: int = ..., | ||||||
| default_auto_archive_duration: ThreadArchiveDuration = ..., | ||||||
| default_thread_slowmode_delay: int = ..., | ||||||
| type: ChannelType = ..., | ||||||
| overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., | ||||||
| spoiler: bool = ..., | ||||||
|
ToothyDev marked this conversation as resolved.
Resolved
|
||||||
| ) -> TextChannel | None: ... | ||||||
|
|
||||||
| @overload | ||||||
|
|
@@ -841,6 +874,10 @@ async def edit(self, *, reason=None, **options): | |||||
| The new channel's position. | ||||||
| nsfw: :class:`bool` | ||||||
| Whether the channel is marked as NSFW. | ||||||
|
|
||||||
| .. note:: | ||||||
| This setting is mutually exclusive with :attr:`spoiler`. Applying this to a spoiler channel will convert it to an NSFW channel. | ||||||
| Passing both as ``True`` will make the channel an NSFW channel. | ||||||
| sync_permissions: :class:`bool` | ||||||
| Whether to sync permissions with the channel's new or pre-existing | ||||||
| category. Defaults to ``False``. | ||||||
|
|
@@ -865,6 +902,13 @@ async def edit(self, *, reason=None, **options): | |||||
| The new default slowmode delay in seconds for threads created in this channel. | ||||||
|
|
||||||
| .. versionadded:: 2.3 | ||||||
| spoiler: :class:`bool` | ||||||
| Whether the channel should be a spoiler channel. Mutually exclusive with :attr:`nsfw`. | ||||||
|
|
||||||
| .. versionadded:: 2.9 | ||||||
|
|
||||||
| .. note:: | ||||||
| Passing both this and ``nsfw`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag. | ||||||
|
|
||||||
| Returns | ||||||
| ------- | ||||||
|
|
@@ -882,6 +926,18 @@ async def edit(self, *, reason=None, **options): | |||||
| HTTPException | ||||||
| Editing the channel failed. | ||||||
| """ | ||||||
| if "spoiler" in options: | ||||||
|
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. The
Contributor
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 just tested this with the current code. Passing
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. Hmm, fine.
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. So just to make sure I understand @ToothyDev, spoiler to nsfw implicitly works fine but nsfw to spoiler implicitly fails ?
Contributor
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. Correct. I think this was a dicussion way early in the PR where catching all the specific cases was really complicated and so it was scrapped, since the API doesn't reject it, it just doesn't do anything
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. It seems like the only explicitly documented behavior is
for spoiler state, and nothing about the other way around. I am not sure however if we should still rely on the API for the rest. @Lulalaby Do you have some insight maybe ?
Contributor
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. @Lulalaby wdyt
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. @ToothyDev Ive been ootl for too long but it seems to me like I can't find here where "nsfw to spoiler implicitly fails" is handled. |
||||||
| options["flags"] = ChannelFlags._from_value(self.flags.value) | ||||||
| options["flags"].is_spoiler_channel = options["spoiler"] | ||||||
|
|
||||||
| if options.get("nsfw") and options.get("spoiler"): | ||||||
|
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.
Suggested change
|
||||||
| warnings.warn( | ||||||
| "The NSFW setting is mutually exclusive with the spoiler setting. " | ||||||
| "The channel will become an NSFW channel.", | ||||||
| stacklevel=2, | ||||||
| ) | ||||||
| options.pop("spoiler") | ||||||
|
|
||||||
| payload = await self._edit(options, reason=reason) | ||||||
| if payload is not None: | ||||||
| # the payload will always be the proper channel payload | ||||||
|
|
@@ -1123,6 +1179,31 @@ async def edit( | |||||
| available_tags: list[ForumTag] = ..., | ||||||
| require_tag: bool = ..., | ||||||
| overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., | ||||||
| spoiler: Literal[False] = ..., | ||||||
| ) -> ForumChannel | None: ... | ||||||
|
|
||||||
| @overload | ||||||
| async def edit( | ||||||
| self, | ||||||
| *, | ||||||
| reason: str | None = ..., | ||||||
| name: str = ..., | ||||||
| topic: str = ..., | ||||||
| position: int = ..., | ||||||
| nsfw: Literal[False] = ..., | ||||||
| sync_permissions: bool = ..., | ||||||
| category: CategoryChannel | None = ..., | ||||||
| slowmode_delay: int = ..., | ||||||
| default_auto_archive_duration: ( | ||||||
| ThreadArchiveDuration | ThreadArchiveDurationEnum | ||||||
| ) = ..., | ||||||
| default_thread_slowmode_delay: int = ..., | ||||||
| default_sort_order: SortOrder = ..., | ||||||
| default_reaction_emoji: GuildEmoji | int | str | None = ..., | ||||||
| available_tags: list[ForumTag] = ..., | ||||||
| require_tag: bool = ..., | ||||||
| overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., | ||||||
| spoiler: bool = ..., | ||||||
| ) -> ForumChannel | None: ... | ||||||
|
|
||||||
| @overload | ||||||
|
|
@@ -1145,7 +1226,10 @@ async def edit(self, *, reason=None, **options): | |||||
| position: :class:`int` | ||||||
| The new channel's position. | ||||||
| nsfw: :class:`bool` | ||||||
| Whether the channel is marked as NSFW. | ||||||
| Whether the channel is marked as NSFW. Mutually exclusive with :attr:`spoiler`. | ||||||
|
|
||||||
| .. note:: | ||||||
| Passing both this and ``spoiler`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag. | ||||||
| sync_permissions: :class:`bool` | ||||||
| Whether to sync permissions with the channel's new or pre-existing | ||||||
| category. Defaults to ``False``. | ||||||
|
|
@@ -1185,6 +1269,13 @@ async def edit(self, *, reason=None, **options): | |||||
| Whether a tag should be required to be specified when creating a thread in this channel. | ||||||
|
|
||||||
| .. versionadded:: 2.3 | ||||||
| spoiler: :class:`bool` | ||||||
| Whether the channel should be a spoiler channel. Mutually exclusive with :attr:`nsfw`. | ||||||
|
Paillat-dev marked this conversation as resolved.
Resolved
|
||||||
|
|
||||||
| .. versionadded:: 2.9 | ||||||
|
ToothyDev marked this conversation as resolved.
Resolved
|
||||||
|
|
||||||
| .. note:: | ||||||
| Passing both this and ``nsfw`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag. | ||||||
|
|
||||||
| Returns | ||||||
| ------- | ||||||
|
|
@@ -1205,6 +1296,19 @@ async def edit(self, *, reason=None, **options): | |||||
| if "require_tag" in options: | ||||||
| options["flags"] = ChannelFlags._from_value(self.flags.value) | ||||||
| options["flags"].require_tag = options.pop("require_tag") | ||||||
| if "spoiler" in options: | ||||||
| if "flags" not in options: | ||||||
| options["flags"] = ChannelFlags._from_value( | ||||||
| self.flags.value | ||||||
| ) # Reconstruct existing flags | ||||||
| options["flags"].is_spoiler_channel = options["spoiler"] | ||||||
|
|
||||||
| if options.get("nsfw") and options.get("spoiler"): | ||||||
|
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. Same comment as above |
||||||
| warnings.warn( | ||||||
| "The NSFW setting is mutually exclusive with the spoiler setting. The channel will become an NSFW channel.", | ||||||
| stacklevel=2, | ||||||
| ) | ||||||
| options.pop("spoiler") | ||||||
|
|
||||||
| payload = await self._edit(options, reason=reason) | ||||||
| if payload is not None: | ||||||
|
|
@@ -1504,10 +1608,31 @@ async def edit( | |||||
| require_tag: bool = ..., | ||||||
| hide_media_download_options: bool = ..., | ||||||
| overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., | ||||||
| spoiler: Literal[False] = ..., | ||||||
| ) -> MediaChannel | None: ... | ||||||
|
|
||||||
| @overload | ||||||
| async def edit(self) -> MediaChannel | None: ... | ||||||
| async def edit( | ||||||
| self, | ||||||
| *, | ||||||
| reason: str | None = ..., | ||||||
| name: str = ..., | ||||||
| topic: str = ..., | ||||||
| position: int = ..., | ||||||
| nsfw: Literal[False] = ..., | ||||||
| sync_permissions: bool = ..., | ||||||
| category: CategoryChannel | None = ..., | ||||||
| slowmode_delay: int = ..., | ||||||
| default_auto_archive_duration: ThreadArchiveDuration = ..., | ||||||
| default_thread_slowmode_delay: int = ..., | ||||||
| default_sort_order: SortOrder = ..., | ||||||
| default_reaction_emoji: GuildEmoji | int | str | None = ..., | ||||||
| available_tags: list[ForumTag] = ..., | ||||||
| require_tag: bool = ..., | ||||||
| hide_media_download_options: bool = ..., | ||||||
| overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., | ||||||
| spoiler: bool = ..., | ||||||
| ) -> MediaChannel | None: ... | ||||||
|
|
||||||
| async def edit(self, *, reason=None, **options): | ||||||
| """|coro| | ||||||
|
|
@@ -1526,7 +1651,10 @@ async def edit(self, *, reason=None, **options): | |||||
| position: :class:`int` | ||||||
| The new channel's position. | ||||||
| nsfw: :class:`bool` | ||||||
| Whether the channel is marked as NSFW. | ||||||
| Whether the channel is marked as NSFW. Mutually exclusive with :attr:`spoiler`. | ||||||
|
|
||||||
| .. note:: | ||||||
| Passing both this and ``spoiler`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag. | ||||||
| sync_permissions: :class:`bool` | ||||||
| Whether to sync permissions with the channel's new or pre-existing | ||||||
| category. Defaults to ``False``. | ||||||
|
|
@@ -1563,6 +1691,14 @@ async def edit(self, *, reason=None, **options): | |||||
| hide_media_download_options: :class:`bool` | ||||||
| Whether media download options should be hidden in this media channel. | ||||||
|
|
||||||
| spoiler: :class:`bool` | ||||||
| Whether the channel should be a spoiler channel. Mutually exclusive with :attr:`nsfw`. | ||||||
|
|
||||||
| .. versionadded:: 2.9 | ||||||
|
|
||||||
|
ToothyDev marked this conversation as resolved.
Resolved
|
||||||
| .. note:: | ||||||
| Passing both this and ``nsfw`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag. | ||||||
|
|
||||||
| Returns | ||||||
| ------- | ||||||
| :class:`.MediaChannel` | :obj:`None` | ||||||
|
|
@@ -1580,14 +1716,20 @@ async def edit(self, *, reason=None, **options): | |||||
| Editing the channel failed. | ||||||
| """ | ||||||
|
|
||||||
| if "require_tag" in options or "hide_media_download_options" in options: | ||||||
| if {"require_tag", "hide_media_download_options", "spoiler"} & options.keys(): | ||||||
| flags = ChannelFlags._from_value(self.flags.value) | ||||||
| flags.require_tag = options.pop("require_tag", flags.require_tag) | ||||||
| flags.hide_media_download_options = options.pop( | ||||||
| "hide_media_download_options", flags.hide_media_download_options | ||||||
| ) | ||||||
| if options.get("nsfw") and options.get("spoiler"): | ||||||
| warnings.warn( | ||||||
| "The NSFW setting is mutually exclusive with the spoiler setting. " | ||||||
| "The channel will become an NSFW channel.", | ||||||
| stacklevel=2, | ||||||
| ) | ||||||
| flags.is_spoiler_channel = options.pop("spoiler", flags.is_spoiler_channel) | ||||||
| options["flags"] = flags | ||||||
|
|
||||||
| payload = await self._edit(options, reason=reason) | ||||||
| if payload is not None: | ||||||
| # the payload will always be the proper channel payload | ||||||
|
|
@@ -1837,19 +1979,30 @@ def is_nsfw(self) -> bool: | |||||
| """Checks if the channel is NSFW.""" | ||||||
| return self.nsfw | ||||||
|
|
||||||
| @property | ||||||
| def spoiler(self) -> bool: | ||||||
|
ToothyDev marked this conversation as resolved.
Resolved
|
||||||
| """Checks if the channel is a spoiler channel. | ||||||
|
|
||||||
|
ToothyDev marked this conversation as resolved.
Resolved
|
||||||
| .. note:: | ||||||
| This is an alias for :attr:`ChannelFlags.is_spoiler_channel`. | ||||||
|
|
||||||
| .. versionadded:: 2.9 | ||||||
| """ | ||||||
| return self.flags.is_spoiler_channel | ||||||
|
|
||||||
| @property | ||||||
| def last_message(self) -> Message | None: | ||||||
| """Fetches the last message from this channel in cache. | ||||||
|
|
||||||
| The message might not be valid or point to an existing message. | ||||||
|
|
||||||
| .. admonition:: Reliable Fetching | ||||||
| :class: helpful | ||||||
| .. admonition:: Reliable Fetching | ||||||
| :class: helpful | ||||||
|
|
||||||
| For a slightly more reliable method of fetching the | ||||||
| last message, consider using either :meth:`history` | ||||||
| or :meth:`fetch_message` with the :attr:`last_message_id` | ||||||
| attribute. | ||||||
| For a slightly more reliable method of fetching the | ||||||
| last message, consider using either :meth:`history` | ||||||
| or :meth:`fetch_message` with the :attr:`last_message_id` | ||||||
| attribute. | ||||||
|
|
||||||
| Returns | ||||||
| ------- | ||||||
|
|
@@ -2118,6 +2271,26 @@ async def edit( | |||||
| slowmode_delay: int = ..., | ||||||
| nsfw: bool = ..., | ||||||
| reason: str | None = ..., | ||||||
| spoiler: Literal[False] = ..., | ||||||
| ) -> VoiceChannel | None: ... | ||||||
|
|
||||||
| @overload | ||||||
| async def edit( | ||||||
| self, | ||||||
| *, | ||||||
| name: str = ..., | ||||||
| bitrate: int = ..., | ||||||
| user_limit: int = ..., | ||||||
| position: int = ..., | ||||||
| sync_permissions: int = ..., | ||||||
|
ToothyDev marked this conversation as resolved.
Resolved
|
||||||
| category: CategoryChannel | None = ..., | ||||||
| overwrites: Mapping[Role | Member, PermissionOverwrite] = ..., | ||||||
| rtc_region: VoiceRegion | None = ..., | ||||||
| video_quality_mode: VideoQualityMode = ..., | ||||||
| slowmode_delay: int = ..., | ||||||
| nsfw: Literal[False] = ..., | ||||||
| reason: str | None = ..., | ||||||
| spoiler: bool = ..., | ||||||
| ) -> VoiceChannel | None: ... | ||||||
|
|
||||||
| @overload | ||||||
|
|
@@ -2176,10 +2349,21 @@ async def edit(self, *, reason=None, **options): | |||||
| A value of `0` disables slowmode. The maximum value possible is `21600`. | ||||||
|
|
||||||
| nsfw: :class:`bool` | ||||||
| Whether the channel is marked as NSFW. | ||||||
| Whether the channel is marked as NSFW. Mutually exclusive with :attr:`spoiler`. | ||||||
|
|
||||||
| .. versionadded:: 2.7 | ||||||
|
|
||||||
| .. note:: | ||||||
| Passing both this and ``spoiler`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag. | ||||||
|
|
||||||
| spoiler: :class:`bool` | ||||||
| Whether the channel should be a spoiler channel. Mutually exclusive with :attr:`nsfw`. | ||||||
|
|
||||||
| .. versionadded:: 2.9 | ||||||
|
|
||||||
| .. note:: | ||||||
| Passing both this and ``nsfw`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag. | ||||||
|
|
||||||
| Returns | ||||||
| ------- | ||||||
| :class:`.VoiceChannel` | :obj:`None` | ||||||
|
|
@@ -2195,6 +2379,16 @@ async def edit(self, *, reason=None, **options): | |||||
| HTTPException | ||||||
| Editing the channel failed. | ||||||
| """ | ||||||
| if "spoiler" in options: | ||||||
| options["flags"] = ChannelFlags._from_value(self.flags.value) | ||||||
| options["flags"].is_spoiler_channel = options["spoiler"] | ||||||
|
|
||||||
| if options.get("nsfw") and options.get("spoiler"): | ||||||
| warnings.warn( | ||||||
| "NSFW setting is mutually exclusive with spoiler setting. Channel will become an NSFW channel.", | ||||||
| stacklevel=2, | ||||||
| ) | ||||||
| options.pop("spoiler") | ||||||
|
|
||||||
| payload = await self._edit(options, reason=reason) | ||||||
| if payload is not None: | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.