Skip to content

Commit

Permalink
feat: infer modal/component callback names from coroutine (#1519)
Browse files Browse the repository at this point in the history
* feat: infer callback decor from coroutine name

* docs: add new logic notation

* chore: add doc notation to component callback definition
  • Loading branch information
i0bs authored Aug 7, 2023
1 parent 8da4f25 commit ebebb07
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions interactions/models/internal/application_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,14 +1162,18 @@ def component_callback(*custom_id: str | re.Pattern) -> Callable[[AsyncCallable]
Your callback will be given a single argument, `ComponentContext`
Note:
This can optionally take a regex pattern, which will be used to match against the custom ID of the component
This can optionally take a regex pattern, which will be used to match against the custom ID of the component.
If you do not supply a `custom_id`, the name of the coroutine will be used instead.
Args:
*custom_id: The custom ID of the component to wait for
"""

def wrapper(func: AsyncCallable) -> ComponentCommand:
custom_id = custom_id or [func.__name__] # noqa: F823

if not asyncio.iscoroutinefunction(func):
raise ValueError("Commands must be coroutines")

Expand All @@ -1188,14 +1192,18 @@ def modal_callback(*custom_id: str | re.Pattern) -> Callable[[AsyncCallable], Mo
Your callback will be given a single argument, `ModalContext`
Note:
This can optionally take a regex pattern, which will be used to match against the custom ID of the modal
This can optionally take a regex pattern, which will be used to match against the custom ID of the modal.
If you do not supply a `custom_id`, the name of the coroutine will be used instead.
Args:
*custom_id: The custom ID of the modal to wait for
"""

def wrapper(func: AsyncCallable) -> ModalCommand:
custom_id = custom_id or [func.__name__] # noqa: F823

if not asyncio.iscoroutinefunction(func):
raise ValueError("Commands must be coroutines")

Expand Down

0 comments on commit ebebb07

Please sign in to comment.