Skip to content

feat: add sort order for forums #1488

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

Merged
merged 2 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions interactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@
ExponentialBackoffSystem,
LeakyBucketSystem,
TokenBucketSystem,
ForumSortOrder,
)
from .api import events
from . import ext
Expand Down Expand Up @@ -458,6 +459,7 @@
"File",
"FlatUIColors",
"FlatUIColours",
"ForumSortOrder",
"ForumLayoutType",
"get_components_ids",
"get_logger",
Expand Down
2 changes: 2 additions & 0 deletions interactions/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
WebhookMixin,
WebhookTypes,
WebSocketOPCode,
ForumSortOrder,
)
from .internal import (
ActiveVoiceState,
Expand Down Expand Up @@ -396,6 +397,7 @@
"File",
"FlatUIColors",
"FlatUIColours",
"ForumSortOrder",
"ForumLayoutType",
"get_components_ids",
"global_autocomplete",
Expand Down
2 changes: 2 additions & 0 deletions interactions/models/discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
VerificationLevel,
VideoQualityMode,
WebSocketOPCode,
ForumSortOrder,
)
from .file import File, open_file, UPLOADABLE_TYPE
from .guild import (
Expand Down Expand Up @@ -226,6 +227,7 @@
"File",
"FlatUIColors",
"FlatUIColours",
"ForumSortOrder",
"ForumLayoutType",
"get_components_ids",
"Guild",
Expand Down
10 changes: 10 additions & 0 deletions interactions/models/discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
StagePrivacyLevel,
MessageFlags,
InviteTargetType,
ForumSortOrder,
ForumLayoutType,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -2394,6 +2396,14 @@ class GuildForum(GuildChannel):
"""The default emoji to react with for posts"""
last_message_id: Optional[Snowflake_Type] = attrs.field(repr=False, default=None)
# TODO: Implement "template" once the API supports them
default_sort_order: Optional[ForumSortOrder] = attrs.field(
repr=False, default=None, converter=ForumSortOrder.converter
)
"""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"""
default_forum_layout: ForumLayoutType = attrs.field(
repr=False, default=ForumLayoutType.NOT_SET, converter=ForumLayoutType
)
"""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"""

@classmethod
def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]:
Expand Down
14 changes: 13 additions & 1 deletion interactions/models/discord/enums.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum, EnumMeta, IntEnum, IntFlag
from functools import reduce
from operator import or_
from typing import Iterator, Tuple, TypeVar, Type
from typing import Iterator, Tuple, TypeVar, Type, Optional

from interactions.client.const import get_logger

Expand All @@ -19,6 +19,7 @@
"DefaultNotificationLevel",
"ExplicitContentFilterLevel",
"ForumLayoutType",
"ForumSortOrder",
"IntegrationExpireBehaviour",
"Intents",
"InteractionPermissionTypes",
Expand Down Expand Up @@ -1046,3 +1047,14 @@ class ForumLayoutType(CursedIntEnum):
NOT_SET = 0
LIST = 1
GALLERY = 2


class ForumSortOrder(CursedIntEnum):
"""The order of a forum channel."""

LATEST_ACTIVITY = 0
CREATION_DATE = 1

@classmethod
def converter(cls, value: Optional[int]) -> "ForumSortOrder":
return None if value is None else cls(value)
4 changes: 4 additions & 0 deletions interactions/models/discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
ScheduledEventType,
SystemChannelFlags,
VerificationLevel,
ForumSortOrder,
)
from .snowflake import (
Snowflake_Type,
Expand Down Expand Up @@ -1023,6 +1024,7 @@ async def create_forum_channel(
default_reaction_emoji: Absent[Union[dict, "models.PartialEmoji", "models.DefaultReaction", str]] = MISSING,
available_tags: Absent["list[dict | models.ThreadTag] | dict | models.ThreadTag"] = MISSING,
layout: ForumLayoutType = ForumLayoutType.NOT_SET,
sort_order: Absent[ForumSortOrder] = MISSING,
reason: Absent[Optional[str]] = MISSING,
) -> "models.GuildForum":
"""
Expand All @@ -1039,6 +1041,7 @@ async def create_forum_channel(
default_reaction_emoji: The default emoji to react with when creating a thread
available_tags: The available tags for this forum channel
layout: The layout of the forum channel
sort_order: The sort order of the forum channel
reason: The reason for creating this channel

Returns:
Expand All @@ -1057,6 +1060,7 @@ async def create_forum_channel(
default_reaction_emoji=models.process_default_reaction(default_reaction_emoji),
available_tags=list_converter(models.process_thread_tag)(available_tags) if available_tags else MISSING,
default_forum_layout=layout,
default_sort_order=sort_order,
reason=reason,
)

Expand Down