Optimise _unwrap_slash_groups and similar
This commit is contained in:
parent
be9e693047
commit
eef8c07379
@ -188,16 +188,17 @@ def _is_submodule(parent: str, child: str) -> bool:
|
|||||||
|
|
||||||
def _unwrap_slash_groups(
|
def _unwrap_slash_groups(
|
||||||
data: ApplicationCommandInteractionData,
|
data: ApplicationCommandInteractionData,
|
||||||
) -> Tuple[str, List[ApplicationCommandInteractionDataOption]]:
|
) -> Tuple[str, Dict[str, ApplicationCommandInteractionDataOption]]:
|
||||||
command_name = data["name"]
|
command_name = data["name"]
|
||||||
command_options = data.get("options") or []
|
command_options: Any = data.get("options") or []
|
||||||
while any(o["type"] in {1, 2} for o in command_options): # type: ignore
|
while True:
|
||||||
for option in command_options: # type: ignore
|
try:
|
||||||
if option["type"] in {1, 2}: # type: ignore
|
option = next(o for o in command_options if o["type"] in {1, 2})
|
||||||
command_name += f' {option["name"]}' # type: ignore
|
except StopIteration:
|
||||||
command_options = option.get("options") or []
|
return command_name, {o["name"]: o for o in command_options}
|
||||||
|
else:
|
||||||
return command_name, command_options
|
command_name += f' {option["name"]}'
|
||||||
|
command_options = option.get("options") or []
|
||||||
|
|
||||||
|
|
||||||
def _quote_string_safe(string: str) -> str:
|
def _quote_string_safe(string: str) -> str:
|
||||||
@ -1299,7 +1300,7 @@ class BotBase(GroupMixin):
|
|||||||
for name, param in command.clean_params.items():
|
for name, param in command.clean_params.items():
|
||||||
if inspect.isclass(param.annotation) and issubclass(param.annotation, FlagConverter):
|
if inspect.isclass(param.annotation) and issubclass(param.annotation, FlagConverter):
|
||||||
for name, flag in param.annotation.get_flags().items():
|
for name, flag in param.annotation.get_flags().items():
|
||||||
option = next((o for o in command_options if o["name"] == name), None)
|
option = command_options.get(name)
|
||||||
|
|
||||||
if option is None:
|
if option is None:
|
||||||
if flag.required:
|
if flag.required:
|
||||||
@ -1310,7 +1311,7 @@ class BotBase(GroupMixin):
|
|||||||
message.content += f" {prefix}{name}{delimiter}{option['value']}" # type: ignore
|
message.content += f" {prefix}{name}{delimiter}{option['value']}" # type: ignore
|
||||||
continue
|
continue
|
||||||
|
|
||||||
option = next((o for o in command_options if o["name"] == name), None)
|
option = command_options.get(name)
|
||||||
if option is None:
|
if option is None:
|
||||||
if param.default is param.empty and not command._is_typing_optional(param.annotation):
|
if param.default is param.empty and not command._is_typing_optional(param.annotation):
|
||||||
raise errors.MissingRequiredArgument(param)
|
raise errors.MissingRequiredArgument(param)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user