Skip to content

Commit

Permalink
feat: Support setting forum layout (#1308)
Browse files Browse the repository at this point in the history
* feat: add forumLayoutType enum

* feat: support specifying forum layout on creation
  • Loading branch information
LordOfPolls authored Mar 24, 2023
1 parent 585e618 commit 8879c85
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 41 deletions.
14 changes: 8 additions & 6 deletions interactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
ChannelSelectMenu,
ChannelType,
check,
ClientUser,
Color,
COLOR_TYPES,
Colour,
Expand All @@ -101,8 +102,6 @@
ComponentContext,
ComponentType,
context_menu,
user_context_menu,
message_context_menu,
ContextMenu,
ContextMenuContext,
Converter,
Expand Down Expand Up @@ -131,6 +130,7 @@
File,
FlatUIColors,
FlatUIColours,
ForumLayoutType,
get_components_ids,
global_autocomplete,
GlobalAutoComplete,
Expand Down Expand Up @@ -199,6 +199,7 @@
MentionableSelectMenu,
MentionType,
Message,
message_context_menu,
MessageableChannelConverter,
MessageableMixin,
MessageActivity,
Expand All @@ -214,7 +215,6 @@
ModalCommand,
ModalContext,
MODEL_TO_CONVERTER,
ClientUser,
NoArgumentConverter,
NSFWLevel,
open_file,
Expand Down Expand Up @@ -314,6 +314,7 @@
Typing,
UPLOADABLE_TYPE,
User,
user_context_menu,
UserConverter,
UserFlags,
UserSelectMenu,
Expand Down Expand Up @@ -394,6 +395,7 @@
"ChannelType",
"check",
"Client",
"ClientUser",
"Color",
"COLOR_TYPES",
"Colour",
Expand All @@ -404,8 +406,6 @@
"ComponentType",
"const",
"context_menu",
"user_context_menu",
"message_context_menu",
"CONTEXT_MENU_NAME_LENGTH",
"ContextMenu",
"ContextMenuContext",
Expand Down Expand Up @@ -444,6 +444,7 @@
"File",
"FlatUIColors",
"FlatUIColours",
"ForumLayoutType",
"get_components_ids",
"get_logger",
"global_autocomplete",
Expand Down Expand Up @@ -519,6 +520,7 @@
"MentionPrefix",
"MentionType",
"Message",
"message_context_menu",
"MessageableChannelConverter",
"MessageableMixin",
"MessageActivity",
Expand All @@ -536,7 +538,6 @@
"ModalCommand",
"ModalContext",
"MODEL_TO_CONVERTER",
"ClientUser",
"NoArgumentConverter",
"NSFWLevel",
"open_file",
Expand Down Expand Up @@ -648,6 +649,7 @@
"Typing",
"UPLOADABLE_TYPE",
"User",
"user_context_menu",
"UserConverter",
"UserFlags",
"UserSelectMenu",
Expand Down
3 changes: 3 additions & 0 deletions interactions/api/http/http_requests/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async def create_guild_channel(
user_limit: int = 0,
rate_limit_per_user: int = 0,
reason: str | None = None,
**kwargs: dict,
) -> discord_typings.ChannelData:
"""
Create a channel in a guild.
Expand All @@ -143,6 +144,7 @@ async def create_guild_channel(
user_limit: The max users that can be in this channel, only for voice
rate_limit_per_user: The time users must wait between sending messages
reason: The reason for creating this channel
kwargs: Additional keyword arguments to pass to the request
Returns:
The created channel object
Expand All @@ -157,6 +159,7 @@ async def create_guild_channel(
"nsfw": nsfw,
"parent_id": int(parent_id) if parent_id else None,
"permission_overwrites": list(permission_overwrites) if permission_overwrites else None,
**kwargs,
}
if channel_type in (ChannelType.GUILD_VOICE, ChannelType.GUILD_STAGE_VOICE):
payload.update(
Expand Down
10 changes: 6 additions & 4 deletions interactions/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
ChannelMention,
ChannelSelectMenu,
ChannelType,
ClientUser,
Color,
COLOR_TYPES,
Colour,
Expand All @@ -56,6 +57,7 @@
File,
FlatUIColors,
FlatUIColours,
ForumLayoutType,
get_components_ids,
Guild,
GuildBan,
Expand Down Expand Up @@ -102,7 +104,6 @@
MessageType,
MFALevel,
Modal,
ClientUser,
NSFWLevel,
open_file,
OverwriteType,
Expand Down Expand Up @@ -344,6 +345,7 @@
"ChannelSelectMenu",
"ChannelType",
"check",
"ClientUser",
"Color",
"COLOR_TYPES",
"Colour",
Expand All @@ -353,8 +355,6 @@
"ComponentContext",
"ComponentType",
"context_menu",
"user_context_menu",
"message_context_menu",
"ContextMenu",
"ContextMenuContext",
"Converter",
Expand Down Expand Up @@ -383,6 +383,7 @@
"File",
"FlatUIColors",
"FlatUIColours",
"ForumLayoutType",
"get_components_ids",
"global_autocomplete",
"GlobalAutoComplete",
Expand Down Expand Up @@ -451,6 +452,7 @@
"MentionableSelectMenu",
"MentionType",
"Message",
"message_context_menu",
"MessageableChannelConverter",
"MessageableMixin",
"MessageActivity",
Expand All @@ -466,7 +468,6 @@
"ModalCommand",
"ModalContext",
"MODEL_TO_CONVERTER",
"ClientUser",
"NoArgumentConverter",
"NSFWLevel",
"open_file",
Expand Down Expand Up @@ -566,6 +567,7 @@
"Typing",
"UPLOADABLE_TYPE",
"User",
"user_context_menu",
"UserConverter",
"UserFlags",
"UserSelectMenu",
Expand Down
4 changes: 3 additions & 1 deletion interactions/models/discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
ComponentType,
DefaultNotificationLevel,
ExplicitContentFilterLevel,
ForumLayoutType,
IntegrationExpireBehaviour,
Intents,
InteractionPermissionTypes,
Expand Down Expand Up @@ -202,6 +203,7 @@
"ChannelMention",
"ChannelSelectMenu",
"ChannelType",
"ClientUser",
"Color",
"COLOR_TYPES",
"Colour",
Expand All @@ -222,6 +224,7 @@
"File",
"FlatUIColors",
"FlatUIColours",
"ForumLayoutType",
"get_components_ids",
"Guild",
"GuildBan",
Expand Down Expand Up @@ -268,7 +271,6 @@
"MessageType",
"MFALevel",
"Modal",
"ClientUser",
"NSFWLevel",
"open_file",
"OverwriteType",
Expand Down
69 changes: 39 additions & 30 deletions interactions/models/discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,48 @@
from interactions.client.const import get_logger

__all__ = (
"WebSocketOPCode",
"Intents",
"UserFlags",
"ActivityFlag",
"ActivityType",
"ApplicationFlags",
"TeamMembershipState",
"PremiumType",
"MemberFlags",
"MessageType",
"MessageActivityType",
"MessageFlags",
"Permissions",
"AuditLogEventType",
"AutoArchiveDuration",
"ButtonStyle",
"ChannelFlags",
"ChannelType",
"ComponentType",
"CommandType",
"InteractionType",
"ButtonStyle",
"MentionType",
"OverwriteType",
"ComponentType",
"DefaultNotificationLevel",
"ExplicitContentFilterLevel",
"ForumLayoutType",
"IntegrationExpireBehaviour",
"Intents",
"InteractionPermissionTypes",
"InteractionType",
"InviteTargetType",
"MemberFlags",
"MentionType",
"MessageActivityType",
"MessageFlags",
"MessageType",
"MFALevel",
"VerificationLevel",
"NSFWLevel",
"OverwriteType",
"Permissions",
"PremiumTier",
"SystemChannelFlags",
"ChannelFlags",
"VideoQualityMode",
"AutoArchiveDuration",
"ActivityType",
"ActivityFlag",
"Status",
"StagePrivacyLevel",
"IntegrationExpireBehaviour",
"InviteTargetType",
"PremiumType",
"ScheduledEventPrivacyLevel",
"ScheduledEventType",
"ScheduledEventStatus",
"AuditLogEventType",
"InteractionPermissionTypes",
"StickerTypes",
"ScheduledEventType",
"StagePrivacyLevel",
"Status",
"StickerFormatType",
"StickerTypes",
"SystemChannelFlags",
"TeamMembershipState",
"UserFlags",
"VerificationLevel",
"VideoQualityMode",
"WebSocketOPCode",
)


Expand Down Expand Up @@ -967,3 +968,11 @@ class StickerFormatType(CursedIntEnum):
APNG = 2
LOTTIE = 3
GIF = 4


class ForumLayoutType(CursedIntEnum):
"""The layout of a forum channel."""

NOT_SET = 0
LIST = 1
GALLERY = 2
7 changes: 7 additions & 0 deletions interactions/models/discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
AuditLogEventType,
AutoModEvent,
AutoModTriggerType,
ForumLayoutType,
)
from .snowflake import to_snowflake, Snowflake_Type, to_optional_snowflake, to_snowflake_list

Expand Down Expand Up @@ -895,6 +896,7 @@ async def create_channel(
user_limit: int = 0,
rate_limit_per_user: int = 0,
reason: Absent[Optional[str]] = MISSING,
**kwargs: dict,
) -> "models.TYPE_GUILD_CHANNEL":
"""
Create a guild channel, allows for explicit channel type setting.
Expand All @@ -911,6 +913,7 @@ async def create_channel(
user_limit: The max users that can be in this channel, only for voice
rate_limit_per_user: The time users must wait between sending messages
reason: The reason for creating this channel
kwargs: Additional keyword arguments to pass to the channel creation
Returns:
The newly created channel.
Expand All @@ -929,6 +932,7 @@ async def create_channel(
user_limit,
rate_limit_per_user,
reason,
**kwargs,
)
return self._client.cache.place_channel_data(channel_data)

Expand Down Expand Up @@ -985,6 +989,7 @@ async def create_forum_channel(
category: Union[Snowflake_Type, "models.GuildCategory"] = None,
nsfw: bool = False,
rate_limit_per_user: int = 0,
layout: ForumLayoutType = ForumLayoutType.NOT_SET,
reason: Absent[Optional[str]] = MISSING,
) -> "models.GuildForum":
"""
Expand All @@ -998,6 +1003,7 @@ async def create_forum_channel(
category: The category this forum channel should be within
nsfw: Should this forum be marked nsfw
rate_limit_per_user: The time users must wait between sending messages
layout: The layout of the forum channel
reason: The reason for creating this channel
Returns:
Expand All @@ -1013,6 +1019,7 @@ async def create_forum_channel(
category=category,
nsfw=nsfw,
rate_limit_per_user=rate_limit_per_user,
default_forum_layout=layout,
reason=reason,
)

Expand Down

0 comments on commit 8879c85

Please sign in to comment.