Skip to content

Commit 6a2d8e6

Browse files
authored
feat: add sort order for forums (#1488)
* feat: add forum sort order * feat: cache layout and sort order for forums
1 parent b299a7f commit 6a2d8e6

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

interactions/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@
339339
ExponentialBackoffSystem,
340340
LeakyBucketSystem,
341341
TokenBucketSystem,
342+
ForumSortOrder,
342343
)
343344
from .api import events
344345
from . import ext
@@ -460,6 +461,7 @@
460461
"File",
461462
"FlatUIColors",
462463
"FlatUIColours",
464+
"ForumSortOrder",
463465
"ForumLayoutType",
464466
"get_components_ids",
465467
"get_logger",

interactions/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
WebhookMixin,
188188
WebhookTypes,
189189
WebSocketOPCode,
190+
ForumSortOrder,
190191
)
191192
from .internal import (
192193
ActiveVoiceState,
@@ -398,6 +399,7 @@
398399
"File",
399400
"FlatUIColors",
400401
"FlatUIColours",
402+
"ForumSortOrder",
401403
"ForumLayoutType",
402404
"get_components_ids",
403405
"global_autocomplete",

interactions/models/discord/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
VerificationLevel,
115115
VideoQualityMode,
116116
WebSocketOPCode,
117+
ForumSortOrder,
117118
)
118119
from .file import File, open_file, UPLOADABLE_TYPE
119120
from .guild import (
@@ -226,6 +227,7 @@
226227
"File",
227228
"FlatUIColors",
228229
"FlatUIColours",
230+
"ForumSortOrder",
229231
"ForumLayoutType",
230232
"get_components_ids",
231233
"Guild",

interactions/models/discord/channel.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
StagePrivacyLevel,
3737
MessageFlags,
3838
InviteTargetType,
39+
ForumSortOrder,
40+
ForumLayoutType,
3941
)
4042

4143
if TYPE_CHECKING:
@@ -2394,6 +2396,14 @@ class GuildForum(GuildChannel):
23942396
"""The default emoji to react with for posts"""
23952397
last_message_id: Optional[Snowflake_Type] = attrs.field(repr=False, default=None)
23962398
# TODO: Implement "template" once the API supports them
2399+
default_sort_order: Optional[ForumSortOrder] = attrs.field(
2400+
repr=False, default=None, converter=ForumSortOrder.converter
2401+
)
2402+
"""the default sort order type used to order posts in GUILD_FORUM channels. Defaults to null, which indicates a preferred sort order hasn't been set by a channel admin"""
2403+
default_forum_layout: ForumLayoutType = attrs.field(
2404+
repr=False, default=ForumLayoutType.NOT_SET, converter=ForumLayoutType
2405+
)
2406+
"""The default forum layout view used to display posts in GUILD_FORUM channels. Defaults to 0, which indicates a layout view has not been set by a channel admin"""
23972407

23982408
@classmethod
23992409
def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]:

interactions/models/discord/enums.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from enum import Enum, EnumMeta, IntEnum, IntFlag
22
from functools import reduce
33
from operator import or_
4-
from typing import Iterator, Tuple, TypeVar, Type
4+
from typing import Iterator, Tuple, TypeVar, Type, Optional
55

66
from interactions.client.const import get_logger
77

@@ -19,6 +19,7 @@
1919
"DefaultNotificationLevel",
2020
"ExplicitContentFilterLevel",
2121
"ForumLayoutType",
22+
"ForumSortOrder",
2223
"IntegrationExpireBehaviour",
2324
"Intents",
2425
"InteractionPermissionTypes",
@@ -1046,3 +1047,14 @@ class ForumLayoutType(CursedIntEnum):
10461047
NOT_SET = 0
10471048
LIST = 1
10481049
GALLERY = 2
1050+
1051+
1052+
class ForumSortOrder(CursedIntEnum):
1053+
"""The order of a forum channel."""
1054+
1055+
LATEST_ACTIVITY = 0
1056+
CREATION_DATE = 1
1057+
1058+
@classmethod
1059+
def converter(cls, value: Optional[int]) -> "ForumSortOrder":
1060+
return None if value is None else cls(value)

interactions/models/discord/guild.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
ScheduledEventType,
4242
SystemChannelFlags,
4343
VerificationLevel,
44+
ForumSortOrder,
4445
)
4546
from .snowflake import (
4647
Snowflake_Type,
@@ -1023,6 +1024,7 @@ async def create_forum_channel(
10231024
default_reaction_emoji: Absent[Union[dict, "models.PartialEmoji", "models.DefaultReaction", str]] = MISSING,
10241025
available_tags: Absent["list[dict | models.ThreadTag] | dict | models.ThreadTag"] = MISSING,
10251026
layout: ForumLayoutType = ForumLayoutType.NOT_SET,
1027+
sort_order: Absent[ForumSortOrder] = MISSING,
10261028
reason: Absent[Optional[str]] = MISSING,
10271029
) -> "models.GuildForum":
10281030
"""
@@ -1039,6 +1041,7 @@ async def create_forum_channel(
10391041
default_reaction_emoji: The default emoji to react with when creating a thread
10401042
available_tags: The available tags for this forum channel
10411043
layout: The layout of the forum channel
1044+
sort_order: The sort order of the forum channel
10421045
reason: The reason for creating this channel
10431046
10441047
Returns:
@@ -1057,6 +1060,7 @@ async def create_forum_channel(
10571060
default_reaction_emoji=models.process_default_reaction(default_reaction_emoji),
10581061
available_tags=list_converter(models.process_thread_tag)(available_tags) if available_tags else MISSING,
10591062
default_forum_layout=layout,
1063+
default_sort_order=sort_order,
10601064
reason=reason,
10611065
)
10621066

0 commit comments

Comments
 (0)