Skip to content

Commit

Permalink
Command localisation support (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
FasterSpeeding authored Oct 15, 2022
1 parent 577a800 commit 0ba037b
Show file tree
Hide file tree
Showing 27 changed files with 4,605 additions and 533 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
no converters or converters which result in a [collections.abc.Sized][] compatible value.
- Support for specifying the length of a string argument in annotation command declaration through
[tanjun.annotations.Length][].
- [AutocompleteContext.triggering_name][tanjun.abc.AutocompleteContext.triggering_name] which acts
like [Context.triggering_name][tanjun.abc.Context.triggering_name].
- Support for localising check responses for application command contexts, and slash command +
context menu declarations (names and descriptions).
More information on how this works can be found in [localisation][].

### Changed
- Bumped the minimum Hikari version to `2.0.0.dev111`.
- Bumped the minimum Alluka version to `0.1.2`.

### Fixed
- Make [tanjun.commands.slash.SlashCommandGroup.as_sub_command][]'s typing more
flexible to allow decorating other command objects.
- `tanjun.context.slash.SlashContext.triggering_name` now returns the full triggering command name
for sub-commands instead of just the top level command's name.
- Optimise [tanjun.checks.OwnPermissionCheck][] to use `context.app_permissions` instead of
calculating the bot's permissions for context menu command calls.

### Removed
- The generic value field from `BaseConverter`.
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Default dependency utilities used within Tanjun and their abstract interfaces.
rendering:
show_root_heading: true

::: tanjun.dependencies.locales
rendering:
show_root_heading: true

::: tanjun.dependencies.owners
rendering:
show_root_heading: true
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def spell_check(session: nox.Session) -> None:
".pre-commit-config.yaml",
"./docs",
"--ignore-regex",
"TimeSchedule",
"TimeSchedule|Nd",
)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
"Topic :: Utilities",
"Typing :: Typed",
]
dependencies = ["alluka~=0.1", "hikari~=2.0.0.dev111"]
dependencies = ["alluka~=0.1.2", "hikari~=2.0.0.dev111"]
dynamic = ["description", "version"]

[project.urls]
Expand Down
21 changes: 12 additions & 9 deletions tanjun/_internal.py → tanjun/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@

import hikari

from . import errors
from ._vendor import inspect
from .. import errors
from .._vendor import inspect

if typing.TYPE_CHECKING:
import typing_extensions

from . import abc as tanjun
from .. import abc as tanjun

_P = typing_extensions.ParamSpec("_P")

Expand Down Expand Up @@ -332,12 +332,14 @@ def collect_wrapped(command: tanjun.ExecutableCommand[typing.Any]) -> list[tanju


_OptionT = typing.TypeVar("_OptionT", bound=hikari.CommandInteractionOption)
_COMMAND_OPTION_TYPES: typing.Final[frozenset[hikari.OptionType]] = frozenset(
SUB_COMMAND_OPTION_TYPES: typing.Final[frozenset[hikari.OptionType]] = frozenset(
[hikari.OptionType.SUB_COMMAND, hikari.OptionType.SUB_COMMAND_GROUP]
)


def flatten_options(options: typing.Optional[collections.Sequence[_OptionT]], /) -> collections.Sequence[_OptionT]:
def flatten_options(
name: str, options: typing.Optional[collections.Sequence[_OptionT]], /
) -> tuple[str, collections.Sequence[_OptionT]]:
"""Flatten the options of a slash/autocomplete interaction.
Parameters
Expand All @@ -347,10 +349,11 @@ def flatten_options(options: typing.Optional[collections.Sequence[_OptionT]], /)
Returns
-------
collections.abc.Sequence[_OptionT]
A sequence of the actual command options.
tuple[str, collections.abc.Sequence[_OptionT]]
The full triggering command name and a sequence of the actual command options.
"""
while options and (first_option := options[0]).type in _COMMAND_OPTION_TYPES:
while options and (first_option := options[0]).type in SUB_COMMAND_OPTION_TYPES:
name = f"{name} {first_option.name}"
options = typing.cast("collections.Sequence[_OptionT]", first_option.options)

return options or ()
return name, options or ()
Loading

0 comments on commit 0ba037b

Please sign in to comment.