-
-
Notifications
You must be signed in to change notification settings - Fork 497
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
Open
ToothyDev
wants to merge
26
commits into
master
Choose a base branch
from
feat/spoiler-channels
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b1ded01
Add spoiler channel flag and functions
ToothyDev 7b79faa
Add editing spoiler flag to channel editing functions
ToothyDev 9d09881
Merge branch 'master' into feat/spoiler-channels
ToothyDev 65bfc90
Merge branch 'master' into feat/spoiler-channels
Lulalaby f426f25
fix: changelog
Lulalaby cb9f534
Merge branch 'master' into feat/spoiler-channels
Lulalaby 7aaad87
Merge branch 'master' into feat/spoiler-channels
ToothyDev 769cc08
Make spoiler attribute a property
ToothyDev 19531ba
Add mutual exclusivity check for nsfw and spoiler options
ToothyDev 16309ed
Merge branch 'master' into feat/spoiler-channels
ToothyDev 68608ab
Adjust changelog to new naming
ToothyDev 763c13f
Merge branch 'master' into feat/spoiler-channels
Lulalaby f2cb6bb
Add channel creation support with spoiler flag
ToothyDev 9508a82
Add channel creation support with spoiler flag
ToothyDev 4f41083
Minor documentation formatting
ToothyDev 7327338
Fix value defaulting
ToothyDev 57e3dd7
Address code review change requests
ToothyDev 06167d2
Warn when passing both nsfw and spoiler options
ToothyDev c8f6f61
Add overloads for voice and forum channels
ToothyDev b56e022
Apply change requests from code review
ToothyDev 2582634
Apply change requests from code review
ToothyDev ccca218
Fix edit() overloads
ToothyDev 74dda97
Address change requests
ToothyDev 0e64964
Merge branch 'master' into feat/spoiler-channels
ToothyDev 8fcaf91
fixup! Merge branch 'master' into feat/spoiler-channels
ToothyDev 414bd34
Address change requests
ToothyDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |||||||||||||||
| from __future__ import annotations | ||||||||||||||||
|
|
||||||||||||||||
| import datetime | ||||||||||||||||
| from _warnings import warn | ||||||||||||||||
|
ToothyDev marked this conversation as resolved.
Outdated
|
||||||||||||||||
| from collections.abc import Callable, Iterable, Mapping, Sequence | ||||||||||||||||
| from typing import ( | ||||||||||||||||
| TYPE_CHECKING, | ||||||||||||||||
|
|
@@ -317,6 +318,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. | ||||||||||||||||
|
ToothyDev marked this conversation as resolved.
|
||||||||||||||||
|
|
||||||||||||||||
| .. note:: | ||||||||||||||||
| This is an alias for :attr:`flags.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. | ||||||||||||||||
|
|
@@ -811,6 +823,24 @@ async def edit( | |||||||||||||||
| overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., | ||||||||||||||||
| ) -> TextChannel | None: ... | ||||||||||||||||
|
|
||||||||||||||||
| @overload | ||||||||||||||||
| async def edit( | ||||||||||||||||
| self, | ||||||||||||||||
| *, | ||||||||||||||||
| reason: str | None = ..., | ||||||||||||||||
| name: str = ..., | ||||||||||||||||
| topic: str = ..., | ||||||||||||||||
| position: int = ..., | ||||||||||||||||
| 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.
|
||||||||||||||||
| ) -> TextChannel | None: ... | ||||||||||||||||
|
|
||||||||||||||||
| @overload | ||||||||||||||||
| async def edit(self) -> TextChannel | None: ... | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -840,7 +870,8 @@ 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`, although | ||||||||||||||||
| this will convert a spoiler channel into an nsfw channel. | ||||||||||||||||
|
Paillat-dev marked this conversation as resolved.
Outdated
ToothyDev marked this conversation as resolved.
Outdated
|
||||||||||||||||
| sync_permissions: :class:`bool` | ||||||||||||||||
| Whether to sync permissions with the channel's new or pre-existing | ||||||||||||||||
| category. Defaults to ``False``. | ||||||||||||||||
|
|
@@ -865,6 +896,11 @@ 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`, although | ||||||||||||||||
| this will convert an nsfw channel into a spoiler channel. | ||||||||||||||||
|
Paillat-dev marked this conversation as resolved.
Outdated
ToothyDev marked this conversation as resolved.
Outdated
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
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. Something along those lines. |
||||||||||||||||
|
|
||||||||||||||||
| .. versionadded:: 2.9 | ||||||||||||||||
|
|
||||||||||||||||
| Returns | ||||||||||||||||
| ------- | ||||||||||||||||
|
|
@@ -882,6 +918,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["spoiler"]: | ||||||||||||||||
| warn( | ||||||||||||||||
| "NSFW setting is mutually exclusive with spoiler setting. Channel will become an NSFW channel." | ||||||||||||||||
|
ToothyDev marked this conversation as resolved.
Outdated
|
||||||||||||||||
| ) | ||||||||||||||||
| options.pop("spoiler") | ||||||||||||||||
|
|
||||||||||||||||
| payload = await self._edit(options, reason=reason) | ||||||||||||||||
| if payload is not None: | ||||||||||||||||
| # the payload will always be the proper channel payload | ||||||||||||||||
|
|
@@ -1125,6 +1171,29 @@ async def edit( | |||||||||||||||
| overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., | ||||||||||||||||
| ) -> ForumChannel | None: ... | ||||||||||||||||
|
|
||||||||||||||||
| @overload | ||||||||||||||||
| async def edit( | ||||||||||||||||
| self, | ||||||||||||||||
| *, | ||||||||||||||||
| reason: str | None = ..., | ||||||||||||||||
| name: str = ..., | ||||||||||||||||
| topic: str = ..., | ||||||||||||||||
| position: int = ..., | ||||||||||||||||
| 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 | ||||||||||||||||
| async def edit(self) -> ForumChannel | None: ... | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -1185,6 +1254,10 @@ 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.
|
||||||||||||||||
|
|
||||||||||||||||
| .. versionadded:: 2.9 | ||||||||||||||||
|
|
||||||||||||||||
| Returns | ||||||||||||||||
| ------- | ||||||||||||||||
|
|
@@ -1205,6 +1278,14 @@ 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 "nsfw" in options: | ||||||||||||||||
|
ToothyDev marked this conversation as resolved.
Outdated
|
||||||||||||||||
| warn( | ||||||||||||||||
| "NSFW setting is mutually exclusive with spoiler setting. Channel will become an NSFW channel." | ||||||||||||||||
|
Paillat-dev marked this conversation as resolved.
Outdated
|
||||||||||||||||
| ) | ||||||||||||||||
| if "flags" not in options: | ||||||||||||||||
| options["flags"] = ChannelFlags._from_value(self.flags.value) | ||||||||||||||||
|
ToothyDev marked this conversation as resolved.
|
||||||||||||||||
| options["flags"].is_spoiler_channel = options.pop("spoiler") | ||||||||||||||||
|
|
||||||||||||||||
| payload = await self._edit(options, reason=reason) | ||||||||||||||||
| if payload is not None: | ||||||||||||||||
|
|
@@ -1504,6 +1585,7 @@ async def edit( | |||||||||||||||
| require_tag: bool = ..., | ||||||||||||||||
| hide_media_download_options: bool = ..., | ||||||||||||||||
| overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., | ||||||||||||||||
| spoiler: bool = ..., | ||||||||||||||||
| ) -> ForumChannel | None: ... | ||||||||||||||||
|
|
||||||||||||||||
| async def edit(self, *, reason=None, **options): | ||||||||||||||||
|
|
@@ -1560,6 +1642,11 @@ 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 | ||||||||||||||||
|
|
||||||||||||||||
| Returns | ||||||||||||||||
| ------- | ||||||||||||||||
| Optional[:class:`.MediaChannel`] | ||||||||||||||||
|
|
@@ -1577,14 +1664,18 @@ 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["spoiler"]: | ||||||||||||||||
|
ToothyDev marked this conversation as resolved.
Outdated
|
||||||||||||||||
| warn( | ||||||||||||||||
| "NSFW setting is mutually exclusive with spoiler setting. Channel will become an NSFW channel." | ||||||||||||||||
|
ToothyDev marked this conversation as resolved.
Outdated
|
||||||||||||||||
| ) | ||||||||||||||||
| 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 | ||||||||||||||||
|
|
@@ -1815,6 +1906,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. | ||||||||||||||||
|
|
||||||||||||||||
|
ToothyDev marked this conversation as resolved.
|
||||||||||||||||
| .. note:: | ||||||||||||||||
| This is an alias for :attr:`flags.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. | ||||||||||||||||
|
|
@@ -2096,6 +2198,7 @@ async def edit( | |||||||||||||||
| slowmode_delay: int = ..., | ||||||||||||||||
| nsfw: bool = ..., | ||||||||||||||||
| reason: str | None = ..., | ||||||||||||||||
| spoiler: bool = ..., | ||||||||||||||||
| ) -> VoiceChannel | None: ... | ||||||||||||||||
|
|
||||||||||||||||
| @overload | ||||||||||||||||
|
|
@@ -2154,6 +2257,11 @@ async def edit(self, *, reason=None, **options): | |||||||||||||||
|
|
||||||||||||||||
| .. versionadded:: 2.7 | ||||||||||||||||
|
|
||||||||||||||||
| spoiler: :class:`bool` | ||||||||||||||||
| Whether the channel should be a spoiler channel. Mutually exclusive with :attr:`nsfw`. | ||||||||||||||||
|
|
||||||||||||||||
| .. versionadded:: 2.9 | ||||||||||||||||
|
|
||||||||||||||||
| Returns | ||||||||||||||||
| ------- | ||||||||||||||||
| Optional[:class:`.VoiceChannel`] | ||||||||||||||||
|
|
@@ -2169,6 +2277,15 @@ 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["spoiler"]: | ||||||||||||||||
| warn( | ||||||||||||||||
| "NSFW setting is mutually exclusive with spoiler setting. Channel will become an NSFW channel." | ||||||||||||||||
| ) | ||||||||||||||||
| options.pop("spoiler") | ||||||||||||||||
|
|
||||||||||||||||
| payload = await self._edit(options, reason=reason) | ||||||||||||||||
| if payload is not None: | ||||||||||||||||
|
|
@@ -2403,6 +2520,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. | ||||||||||||||||
|
|
||||||||||||||||
|
ToothyDev marked this conversation as resolved.
|
||||||||||||||||
| .. note:: | ||||||||||||||||
| This is an alias for :attr:`flags.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. | ||||||||||||||||
|
|
||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it lowercase cause that seems to be the convention in the rest of the docs