Skip to content
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

refactor: Minor parameter catching #463

Merged
merged 14 commits into from Feb 9, 2022
4 changes: 2 additions & 2 deletions interactions/api/models/member.py
Expand Up @@ -74,12 +74,12 @@ def __init__(self, **kwargs):

if not self.avatar and self.user:
self.avatar = self.user.avatar

@property
def id(self) -> Snowflake:
"""
Returns the ID of the user.

:return: The ID of the user
:rtype: Snowflake
"""
Expand Down
61 changes: 55 additions & 6 deletions interactions/client.py
Expand Up @@ -20,7 +20,7 @@
from .base import get_logger
from .decor import command
from .decor import component as _component
from .enums import ApplicationCommandType
from .enums import ApplicationCommandType, OptionType
from .models.command import ApplicationCommand, Option
from .models.component import Button, Modal, SelectMenu

Expand Down Expand Up @@ -380,6 +380,22 @@ def decorator(coro: Coroutine) -> Callable[..., Any]:
if name is MISSING:
raise InteractionException(11, message="Your command must have a name.")

elif len(name) > 32:
raise InteractionException(
11, message="Command name must not be more than 32 characters."
V3ntus marked this conversation as resolved.
Show resolved Hide resolved
)
elif len(description) > 100:
raise InteractionException(
11, message="Command description must be less than 100 characters"
V3ntus marked this conversation as resolved.
Show resolved Hide resolved
)

for _ in name:
if _.isupper():
raise InteractionException(
11,
message="Your command name must not contain uppercase characters (Discord limitation)",
)

if type == ApplicationCommandType.CHAT_INPUT and description is MISSING:
raise InteractionException(
11, message="Chat-input commands must have a description."
Expand All @@ -389,11 +405,44 @@ def decorator(coro: Coroutine) -> Callable[..., Any]:
raise InteractionException(
11, message="Your command needs at least one argument to return context."
)
if options is not MISSING and len(coro.__code__.co_varnames) + 1 < len(options):
raise InteractionException(
11,
message="You must have the same amount of arguments as the options of the command.",
)
if options is not MISSING:
if len(coro.__code__.co_varnames) + 1 < len(options):
raise InteractionException(
11,
message="You must have the same amount of arguments as the options of the command.",
)
if isinstance(options, List) and len(options) > 25:
raise InteractionException(
11, message="You cannot have more than 25 options in a command"
)
_option: Option
for _option in options:
if _option.type not in (
OptionType.SUB_COMMAND,
OptionType.SUB_COMMAND_GROUP,
):
if getattr(_option, "autocomplete", False) and getattr(
_option, "choices", False
):
raise InteractionException(
11,
message="Autocomplete may not be set to true if choices are present",
V3ntus marked this conversation as resolved.
Show resolved Hide resolved
)
if not getattr(_option, "description", False):
raise InteractionException(
11,
message="A description is required for Options that are not sub-commands",
)
if len(_option.description) > 100:
raise InteractionException(
11,
message="Command option descriptions must be less than 100 characters",
)

if len(_option.name) > 32:
raise InteractionException(
11, message="Command option name must be less than 32 characters"
V3ntus marked this conversation as resolved.
Show resolved Hide resolved
)

commands: List[ApplicationCommand] = command(
type=type,
Expand Down