mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-06 10:02:01 +00:00
Add support for ForumChannel.default_layout
This commit is contained in:
parent
9930c672bb
commit
cbc46e0973
@ -47,7 +47,7 @@ import datetime
|
|||||||
import discord.abc
|
import discord.abc
|
||||||
from .scheduled_event import ScheduledEvent
|
from .scheduled_event import ScheduledEvent
|
||||||
from .permissions import PermissionOverwrite, Permissions
|
from .permissions import PermissionOverwrite, Permissions
|
||||||
from .enums import ChannelType, PrivacyLevel, try_enum, VideoQualityMode, EntityType
|
from .enums import ChannelType, ForumLayoutType, PrivacyLevel, try_enum, VideoQualityMode, EntityType
|
||||||
from .mixins import Hashable
|
from .mixins import Hashable
|
||||||
from . import utils
|
from . import utils
|
||||||
from .utils import MISSING
|
from .utils import MISSING
|
||||||
@ -2140,6 +2140,11 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
add reaction button.
|
add reaction button.
|
||||||
|
|
||||||
.. versionadded:: 2.1
|
.. versionadded:: 2.1
|
||||||
|
default_layout: :class:`ForumLayoutType`
|
||||||
|
The default layout for posts in this forum channel.
|
||||||
|
Defaults to :attr:`ForumLayoutType.not_set`.
|
||||||
|
|
||||||
|
.. versionadded:: 2.2
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
@ -2158,6 +2163,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
'default_auto_archive_duration',
|
'default_auto_archive_duration',
|
||||||
'default_thread_slowmode_delay',
|
'default_thread_slowmode_delay',
|
||||||
'default_reaction_emoji',
|
'default_reaction_emoji',
|
||||||
|
'default_layout',
|
||||||
'_available_tags',
|
'_available_tags',
|
||||||
'_flags',
|
'_flags',
|
||||||
)
|
)
|
||||||
@ -2191,6 +2197,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
# This takes advantage of the fact that dicts are ordered since Python 3.7
|
# This takes advantage of the fact that dicts are ordered since Python 3.7
|
||||||
tags = [ForumTag.from_data(state=self._state, data=tag) for tag in data.get('available_tags', [])]
|
tags = [ForumTag.from_data(state=self._state, data=tag) for tag in data.get('available_tags', [])]
|
||||||
self.default_thread_slowmode_delay: int = data.get('default_thread_rate_limit_per_user', 0)
|
self.default_thread_slowmode_delay: int = data.get('default_thread_rate_limit_per_user', 0)
|
||||||
|
self.default_layout: ForumLayoutType = try_enum(ForumLayoutType, data.get('default_forum_layout', 0))
|
||||||
self._available_tags: Dict[int, ForumTag] = {tag.id: tag for tag in tags}
|
self._available_tags: Dict[int, ForumTag] = {tag.id: tag for tag in tags}
|
||||||
|
|
||||||
self.default_reaction_emoji: Optional[PartialEmoji] = None
|
self.default_reaction_emoji: Optional[PartialEmoji] = None
|
||||||
@ -2327,6 +2334,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
available_tags: Sequence[ForumTag] = ...,
|
available_tags: Sequence[ForumTag] = ...,
|
||||||
default_thread_slowmode_delay: int = ...,
|
default_thread_slowmode_delay: int = ...,
|
||||||
default_reaction_emoji: Optional[EmojiInputType] = ...,
|
default_reaction_emoji: Optional[EmojiInputType] = ...,
|
||||||
|
default_layout: ForumLayoutType = ...,
|
||||||
require_tag: bool = ...,
|
require_tag: bool = ...,
|
||||||
) -> ForumChannel:
|
) -> ForumChannel:
|
||||||
...
|
...
|
||||||
@ -2381,6 +2389,10 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
The new default reaction emoji for threads in this channel.
|
The new default reaction emoji for threads in this channel.
|
||||||
|
|
||||||
.. versionadded:: 2.1
|
.. versionadded:: 2.1
|
||||||
|
default_layout: :class:`ForumLayoutType`
|
||||||
|
The new default layout for posts in this forum.
|
||||||
|
|
||||||
|
.. versionadded:: 2.2
|
||||||
require_tag: :class:`bool`
|
require_tag: :class:`bool`
|
||||||
Whether to require a tag for threads in this channel or not.
|
Whether to require a tag for threads in this channel or not.
|
||||||
|
|
||||||
@ -2391,7 +2403,8 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
ValueError
|
ValueError
|
||||||
The new ``position`` is less than 0 or greater than the number of channels.
|
The new ``position`` is less than 0 or greater than the number of channels.
|
||||||
TypeError
|
TypeError
|
||||||
The permission overwrite information is not in proper form.
|
The permission overwrite information is not in proper form or a type
|
||||||
|
is not the expected type.
|
||||||
Forbidden
|
Forbidden
|
||||||
You do not have permissions to edit the forum.
|
You do not have permissions to edit the forum.
|
||||||
HTTPException
|
HTTPException
|
||||||
@ -2432,6 +2445,16 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
flags.require_tag = require_tag
|
flags.require_tag = require_tag
|
||||||
options['flags'] = flags.value
|
options['flags'] = flags.value
|
||||||
|
|
||||||
|
try:
|
||||||
|
layout = options.pop('default_layout')
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if not isinstance(layout, ForumLayoutType):
|
||||||
|
raise TypeError(f'default_layout parameter must be a ForumLayoutType not {layout.__class__.__name__}')
|
||||||
|
|
||||||
|
options['default_forum_layout'] = layout.value
|
||||||
|
|
||||||
payload = await self._edit(options, reason=reason)
|
payload = await self._edit(options, reason=reason)
|
||||||
if payload is not None:
|
if payload is not None:
|
||||||
# the payload will always be the proper channel payload
|
# the payload will always be the proper channel payload
|
||||||
|
@ -66,6 +66,7 @@ __all__ = (
|
|||||||
'AutoModRuleTriggerType',
|
'AutoModRuleTriggerType',
|
||||||
'AutoModRuleEventType',
|
'AutoModRuleEventType',
|
||||||
'AutoModRuleActionType',
|
'AutoModRuleActionType',
|
||||||
|
'ForumLayoutType',
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -734,6 +735,12 @@ class AutoModRuleActionType(Enum):
|
|||||||
timeout = 3
|
timeout = 3
|
||||||
|
|
||||||
|
|
||||||
|
class ForumLayoutType(Enum):
|
||||||
|
not_set = 0
|
||||||
|
list_view = 1
|
||||||
|
gallery_view = 2
|
||||||
|
|
||||||
|
|
||||||
def create_unknown_value(cls: Type[E], val: Any) -> E:
|
def create_unknown_value(cls: Type[E], val: Any) -> E:
|
||||||
value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below
|
value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below
|
||||||
name = f'unknown_{val}'
|
name = f'unknown_{val}'
|
||||||
|
@ -1147,6 +1147,7 @@ class HTTPClient:
|
|||||||
'default_reaction_emoji',
|
'default_reaction_emoji',
|
||||||
'available_tags',
|
'available_tags',
|
||||||
'applied_tags',
|
'applied_tags',
|
||||||
|
'default_forum_layout',
|
||||||
)
|
)
|
||||||
|
|
||||||
payload = {k: v for k, v in options.items() if k in valid_keys}
|
payload = {k: v for k, v in options.items() if k in valid_keys}
|
||||||
|
@ -134,10 +134,14 @@ class ForumTag(TypedDict):
|
|||||||
emoji_name: Optional[str]
|
emoji_name: Optional[str]
|
||||||
|
|
||||||
|
|
||||||
|
ForumLayoutType = Literal[0, 1, 2]
|
||||||
|
|
||||||
|
|
||||||
class ForumChannel(_BaseTextChannel):
|
class ForumChannel(_BaseTextChannel):
|
||||||
type: Literal[15]
|
type: Literal[15]
|
||||||
available_tags: List[ForumTag]
|
available_tags: List[ForumTag]
|
||||||
default_reaction_emoji: Optional[DefaultReaction]
|
default_reaction_emoji: Optional[DefaultReaction]
|
||||||
|
default_forum_layout: NotRequired[ForumLayoutType]
|
||||||
flags: NotRequired[int]
|
flags: NotRequired[int]
|
||||||
|
|
||||||
|
|
||||||
|
20
docs/api.rst
20
docs/api.rst
@ -3210,6 +3210,26 @@ of :class:`enum.Enum`.
|
|||||||
|
|
||||||
The rule will timeout a user.
|
The rule will timeout a user.
|
||||||
|
|
||||||
|
|
||||||
|
.. class:: ForumLayoutType
|
||||||
|
|
||||||
|
Represents how a forum's posts are layed out in the client.
|
||||||
|
|
||||||
|
.. versionadded:: 2.2
|
||||||
|
|
||||||
|
.. attribute:: not_set
|
||||||
|
|
||||||
|
No default has been set, so it is up to the client to know how to lay it out.
|
||||||
|
|
||||||
|
.. attribute:: list_view
|
||||||
|
|
||||||
|
Displays posts as a list.
|
||||||
|
|
||||||
|
.. attribute:: gallery_view
|
||||||
|
|
||||||
|
Displays posts as a collection of tiles.
|
||||||
|
|
||||||
|
|
||||||
.. _discord-api-audit-logs:
|
.. _discord-api-audit-logs:
|
||||||
|
|
||||||
Audit Log Data
|
Audit Log Data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user