Skip to content

Commit

Permalink
Update core.py
Browse files Browse the repository at this point in the history
Signed-off-by: plun1331 <[email protected]>
  • Loading branch information
plun1331 authored Jan 28, 2024
1 parent 5610dd8 commit 365df9b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,8 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:

self.attached_to_group: bool = False

self.options: list[Option] = kwargs.get("options", [])
self._options_kwargs = kwargs.get("options", [])
self.options: list[Option] = []
self._validate_parameters()

try:
Expand All @@ -703,11 +704,13 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
self._after_invoke = None

def _validate_parameters(self):
print(self.options, self._options_kwargs)
params = self._get_signature_parameters()
if kwop := self.options:
if kwop := self._options_kwargs:
self.options = self._match_option_param_names(params, kwop)
else:
self.options = self._parse_options(params)
print(self.options, self._options_kwargs)

def _check_required_params(self, params):
params = iter(params.items())
Expand All @@ -727,6 +730,8 @@ def _check_required_params(self, params):
def _parse_options(self, params, *, check_params: bool = True) -> list[Option]:
if check_params:
params = self._check_required_params(params)
else:
params = iter(params.items())

final_options = []
for p_name, p_obj in params:
Expand Down Expand Up @@ -790,6 +795,7 @@ def _parse_options(self, params, *, check_params: bool = True) -> list[Option]:
return final_options

def _match_option_param_names(self, params, options):
options = list(options)
params = self._check_required_params(params)

check_annotations: list[Callable[[Option, type], bool]] = [
Expand Down Expand Up @@ -855,8 +861,7 @@ def cog(self, value):
or value is None
and old_cog is not None
):
params = self._get_signature_parameters()
self.options = self._parse_options(params)
self._validate_parameters()

@property
def is_subcommand(self) -> bool:
Expand Down

0 comments on commit 365df9b

Please sign in to comment.