Skip to content
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
4 changes: 4 additions & 0 deletions interactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
ComponentContext,
ComponentType,
context_menu,
user_context_menu,
message_context_menu,
ContextMenu,
ContextMenuContext,
Converter,
Expand Down Expand Up @@ -402,6 +404,8 @@
"ComponentType",
"const",
"context_menu",
"user_context_menu",
"message_context_menu",
"CONTEXT_MENU_NAME_LENGTH",
"ContextMenu",
"ContextMenuContext",
Expand Down
4 changes: 4 additions & 0 deletions interactions/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@
ComponentCommand,
ComponentContext,
context_menu,
user_context_menu,
message_context_menu,
ContextMenu,
ContextMenuContext,
Converter,
Expand Down Expand Up @@ -351,6 +353,8 @@
"ComponentContext",
"ComponentType",
"context_menu",
"user_context_menu",
"message_context_menu",
"ContextMenu",
"ContextMenuContext",
"Converter",
Expand Down
4 changes: 4 additions & 0 deletions interactions/models/internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
component_callback,
ComponentCommand,
context_menu,
user_context_menu,
message_context_menu,
ContextMenu,
global_autocomplete,
GlobalAutoComplete,
Expand Down Expand Up @@ -111,6 +113,8 @@
"ComponentCommand",
"ComponentContext",
"context_menu",
"user_context_menu",
"message_context_menu",
"ContextMenu",
"ContextMenuContext",
"Converter",
Expand Down
95 changes: 85 additions & 10 deletions interactions/models/internal/application_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"component_callback",
"ComponentCommand",
"context_menu",
"user_context_menu",
"message_context_menu",
"ContextMenu",
"global_autocomplete",
"GlobalAutoComplete",
Expand Down Expand Up @@ -725,7 +727,7 @@ def group(

def subcommand(
self,
sub_cmd_name: LocalisedName | str,
sub_cmd_name: Absent[LocalisedName | str] = MISSING,
group_name: LocalisedName | str = None,
sub_cmd_description: Absent[LocalisedDesc | str] = MISSING,
group_description: Absent[LocalisedDesc | str] = MISSING,
Expand All @@ -734,13 +736,15 @@ def subcommand(
inherit_checks: bool = True,
) -> Callable[..., "SlashCommand"]:
def wrapper(call: Callable[..., Coroutine]) -> "SlashCommand":
nonlocal sub_cmd_description
nonlocal sub_cmd_name, sub_cmd_description

if not asyncio.iscoroutinefunction(call):
raise TypeError("Subcommand must be coroutine")

if sub_cmd_description is MISSING:
sub_cmd_description = call.__doc__ or "No Description Set"
if sub_cmd_name is MISSING:
sub_cmd_name = call.__name__

return SlashCommand(
name=self.name,
Expand Down Expand Up @@ -863,7 +867,7 @@ def decorator(func: Callable) -> GlobalAutoComplete:


def slash_command(
name: str | LocalisedName,
name: Absent[str | LocalisedName] = MISSING,
*,
description: Absent[str | LocalisedDesc] = MISSING,
scopes: Absent[List["Snowflake_Type"]] = MISSING,
Expand All @@ -885,7 +889,7 @@ def slash_command(
one of the future ui updates.

Args:
name: 1-32 character name of the command
name: 1-32 character name of the command, defaults to the name of the coroutine.
description: 1-100 character description of the command
scopes: The scope this command exists within
options: The parameters for the command, max 25
Expand Down Expand Up @@ -913,12 +917,16 @@ def wrapper(func: AsyncCallable) -> SlashCommand:
else:
perm = func.default_member_permissions

_name = name
if _name is MISSING:
_name = func.__name__

_description = description
if _description is MISSING:
_description = func.__doc__ or "No Description Set"

cmd = SlashCommand(
name=name,
name=_name,
group_name=group_name,
group_description=group_description,
sub_cmd_name=sub_cmd_name,
Expand All @@ -941,7 +949,7 @@ def subcommand(
base: str | LocalisedName,
*,
subcommand_group: Optional[str | LocalisedName] = None,
name: Optional[str | LocalisedName] = None,
name: Absent[str | LocalisedName] = MISSING,
description: Absent[str | LocalisedDesc] = MISSING,
base_description: Optional[str | LocalisedDesc] = None,
base_desc: Optional[str | LocalisedDesc] = None,
Expand Down Expand Up @@ -980,6 +988,10 @@ def wrapper(func: AsyncCallable) -> SlashCommand:
if not asyncio.iscoroutinefunction(func):
raise ValueError("Commands must be coroutines")

_name = name
if _name is MISSING:
_name = func.__name__

_description = description
if _description is MISSING:
_description = func.__doc__ or "No Description Set"
Expand All @@ -989,7 +1001,7 @@ def wrapper(func: AsyncCallable) -> SlashCommand:
description=(base_description or base_desc) or "No Description Set",
group_name=subcommand_group,
group_description=(subcommand_group_description or sub_group_desc) or "No Description Set",
sub_cmd_name=name,
sub_cmd_name=_name,
sub_cmd_description=_description,
default_member_permissions=base_default_member_permissions,
dm_permission=base_dm_permission,
Expand All @@ -1004,7 +1016,8 @@ def wrapper(func: AsyncCallable) -> SlashCommand:


def context_menu(
name: str | LocalisedName,
name: Absent[str | LocalisedName] = MISSING,
*,
context_type: "CommandType",
scopes: Absent[List["Snowflake_Type"]] = MISSING,
default_member_permissions: Optional["Permissions"] = None,
Expand All @@ -1014,7 +1027,7 @@ def context_menu(
A decorator to declare a coroutine as a Context Menu.

Args:
name: 1-32 character name of the context menu
name: 1-32 character name of the context menu, defaults to the name of the coroutine.
context_type: The type of context menu
scopes: The scope this command exists within
default_member_permissions: What permissions members need to have by default to use this command.
Expand All @@ -1036,8 +1049,12 @@ def wrapper(func: AsyncCallable) -> ContextMenu:
else:
perm = func.default_member_permissions

_name = name
if _name is MISSING:
_name = func.__name__

cmd = ContextMenu(
name=name,
name=_name,
type=context_type,
scopes=scopes or [GLOBAL_SCOPE],
default_member_permissions=perm,
Expand All @@ -1049,6 +1066,64 @@ def wrapper(func: AsyncCallable) -> ContextMenu:
return wrapper


def user_context_menu(
name: Absent[str | LocalisedName] = MISSING,
*,
scopes: Absent[List["Snowflake_Type"]] = MISSING,
default_member_permissions: Optional["Permissions"] = None,
dm_permission: bool = True,
) -> Callable[[AsyncCallable], ContextMenu]:
"""
A decorator to declare a coroutine as a User Context Menu.

Args:
name: 1-32 character name of the context menu, defaults to the name of the coroutine.
scopes: The scope this command exists within
default_member_permissions: What permissions members need to have by default to use this command.
dm_permission: Should this command be available in DMs.

Returns:
ContextMenu object

"""
return context_menu(
name,
context_type=CommandType.USER,
scopes=scopes,
default_member_permissions=default_member_permissions,
dm_permission=dm_permission,
)


def message_context_menu(
name: Absent[str | LocalisedName] = MISSING,
*,
scopes: Absent[List["Snowflake_Type"]] = MISSING,
default_member_permissions: Optional["Permissions"] = None,
dm_permission: bool = True,
) -> Callable[[AsyncCallable], ContextMenu]:
"""
A decorator to declare a coroutine as a Message Context Menu.

Args:
name: 1-32 character name of the context menu, defaults to the name of the coroutine.
scopes: The scope this command exists within
default_member_permissions: What permissions members need to have by default to use this command.
dm_permission: Should this command be available in DMs.

Returns:
ContextMenu object

"""
return context_menu(
name,
context_type=CommandType.MESSAGE,
scopes=scopes,
default_member_permissions=default_member_permissions,
dm_permission=dm_permission,
)


def component_callback(*custom_id: str) -> Callable[[AsyncCallable], ComponentCommand]:
"""
Register a coroutine as a component callback.
Expand Down