Skip to content

Commit a611a27

Browse files
committed
feat: Extend __check_command to name localisations per command/option
1 parent 33d2f3f commit a611a27

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

interactions/client/bot.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,17 @@ def __check_sub_group(_sub_group: Option):
397397
raise InteractionException(
398398
11, message="Descriptions must be less than 100 characters."
399399
)
400+
if (
401+
_sub_group.name_localizations is not MISSING
402+
and _sub_group.name_localizations is not None
403+
):
404+
for __name in command.name_localizations.values():
405+
if not re.fullmatch(reg, __name):
406+
raise InteractionException(
407+
11,
408+
message=f"The sub command group name does not match the regex for valid names ('{regex}')",
409+
)
410+
400411
if not _sub_group.options:
401412
raise InteractionException(11, message="sub command groups must have subcommands!")
402413
if len(_sub_group.options) > 25:
@@ -432,6 +443,17 @@ def __check_sub_command(_sub_command: Option, _sub_group: Option = MISSING):
432443
raise InteractionException(
433444
11, message="Descriptions must be less than 100 characters."
434445
)
446+
if (
447+
_sub_command.name_localizations is not MISSING
448+
and _sub_command.name_localizations is not None
449+
):
450+
for __name in command.name_localizations.values():
451+
if not re.fullmatch(reg, __name):
452+
raise InteractionException(
453+
11,
454+
message=f"The sub command name does not match the regex for valid names ('{regex}')",
455+
)
456+
435457
if _sub_command.options is not MISSING and _sub_command.options:
436458
if len(_sub_command.options) > 25:
437459
raise InteractionException(
@@ -478,6 +500,14 @@ def __check_options(_option: Option, _names: list, _sub_command: Option = MISSIN
478500
raise InteractionException(
479501
11, message="You must not have two options with the same name in a command!"
480502
)
503+
if _option.name_localizations is not MISSING and _option.name_localizations is not None:
504+
for __name in _option.name_localizations.values():
505+
if not re.fullmatch(reg, __name):
506+
raise InteractionException(
507+
11,
508+
message=f"The option name does not match the regex for valid names ('{regex}')",
509+
)
510+
481511
_names.append(_option.name)
482512

483513
def __check_coro():
@@ -535,6 +565,14 @@ def __check_coro():
535565
elif command.description is not MISSING and len(command.description) > 100:
536566
raise InteractionException(11, message="Descriptions must be less than 100 characters.")
537567

568+
if command.name_localizations is not MISSING and command.name_localizations is not None:
569+
for __name in command.name_localizations.values():
570+
if not re.fullmatch(reg, __name):
571+
raise InteractionException(
572+
11,
573+
message=f"One of your command name localisations does not match the regex for valid names ('{regex}')",
574+
)
575+
538576
if command.options and command.options is not MISSING:
539577
if len(command.options) > 25:
540578
raise InteractionException(

0 commit comments

Comments
 (0)