Browse Source

Add support for ForumChannel.default_layout

pull/9171/head
Rapptz 2 years ago
parent
commit
cbc46e0973
  1. 27
      discord/channel.py
  2. 7
      discord/enums.py
  3. 1
      discord/http.py
  4. 4
      discord/types/channel.py
  5. 20
      docs/api.rst

27
discord/channel.py

@ -47,7 +47,7 @@ import datetime
import discord.abc
from .scheduled_event import ScheduledEvent
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 . import utils
from .utils import MISSING
@ -2140,6 +2140,11 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
add reaction button.
.. 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__ = (
@ -2158,6 +2163,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
'default_auto_archive_duration',
'default_thread_slowmode_delay',
'default_reaction_emoji',
'default_layout',
'_available_tags',
'_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
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_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.default_reaction_emoji: Optional[PartialEmoji] = None
@ -2327,6 +2334,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
available_tags: Sequence[ForumTag] = ...,
default_thread_slowmode_delay: int = ...,
default_reaction_emoji: Optional[EmojiInputType] = ...,
default_layout: ForumLayoutType = ...,
require_tag: bool = ...,
) -> ForumChannel:
...
@ -2381,6 +2389,10 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
The new default reaction emoji for threads in this channel.
.. versionadded:: 2.1
default_layout: :class:`ForumLayoutType`
The new default layout for posts in this forum.
.. versionadded:: 2.2
require_tag: :class:`bool`
Whether to require a tag for threads in this channel or not.
@ -2391,7 +2403,8 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
ValueError
The new ``position`` is less than 0 or greater than the number of channels.
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
You do not have permissions to edit the forum.
HTTPException
@ -2432,6 +2445,16 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
flags.require_tag = require_tag
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)
if payload is not None:
# the payload will always be the proper channel payload

7
discord/enums.py

@ -66,6 +66,7 @@ __all__ = (
'AutoModRuleTriggerType',
'AutoModRuleEventType',
'AutoModRuleActionType',
'ForumLayoutType',
)
if TYPE_CHECKING:
@ -734,6 +735,12 @@ class AutoModRuleActionType(Enum):
timeout = 3
class ForumLayoutType(Enum):
not_set = 0
list_view = 1
gallery_view = 2
def create_unknown_value(cls: Type[E], val: Any) -> E:
value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below
name = f'unknown_{val}'

1
discord/http.py

@ -1147,6 +1147,7 @@ class HTTPClient:
'default_reaction_emoji',
'available_tags',
'applied_tags',
'default_forum_layout',
)
payload = {k: v for k, v in options.items() if k in valid_keys}

4
discord/types/channel.py

@ -134,10 +134,14 @@ class ForumTag(TypedDict):
emoji_name: Optional[str]
ForumLayoutType = Literal[0, 1, 2]
class ForumChannel(_BaseTextChannel):
type: Literal[15]
available_tags: List[ForumTag]
default_reaction_emoji: Optional[DefaultReaction]
default_forum_layout: NotRequired[ForumLayoutType]
flags: NotRequired[int]

20
docs/api.rst

@ -3210,6 +3210,26 @@ of :class:`enum.Enum`.
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:
Audit Log Data

Loading…
Cancel
Save