Skip to content

Commit

Permalink
Application command localization (#283)
Browse files Browse the repository at this point in the history
Co-authored-by: thomm.o <olijdthompson@gmail.com>
Co-authored-by: emirsurmen <emirsurmen@gmail.com>
  • Loading branch information
3 people committed Nov 10, 2022
1 parent e2eb7c8 commit 2ca2239
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lightbulb/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ class OptionLike:
"""
autocomplete: bool = False
"""Whether the option should be autocompleted or not. This only affects slash commands."""
name_localizations: t.Mapping[t.Union[hikari.Locale, str], str] = dataclasses.field(default_factory=dict)
"""
A mapping of locale to name localizations for this option
.. versionadded:: 2.3.0
"""
description_localizations: t.Mapping[t.Union[hikari.Locale, str], str] = dataclasses.field(default_factory=dict)
"""
A mapping of locale to description localizations for this option
.. versionadded:: 2.3.0
"""

def as_application_command_option(self) -> hikari.CommandOption:
"""
Expand Down Expand Up @@ -215,6 +227,8 @@ def as_application_command_option(self) -> hikari.CommandOption:
"description": self.description,
"is_required": self.required,
"autocomplete": self.autocomplete,
"name_localizations": self.name_localizations,
"description_localizations": self.description_localizations,
}

if self.choices:
Expand Down Expand Up @@ -288,6 +302,18 @@ class CommandLike:
"""Whether this command will be enabled in DMs, if an application command."""
app_command_bypass_author_permission_checks: bool = False
"""Whether invocations of this command will bypass author permission checks, if an application command."""
name_localizations: t.Mapping[t.Union[hikari.Locale, str], str] = dataclasses.field(default_factory=dict)
"""
A mapping of locale to name localizations for this command
.. versionadded:: 2.3.0
"""
description_localizations: t.Mapping[t.Union[hikari.Locale, str], str] = dataclasses.field(default_factory=dict)
"""
A mapping of locale to description localizations for this command
.. versionadded:: 2.3.0
"""
_autocomplete_callbacks: t.Dict[
str,
t.Callable[
Expand Down Expand Up @@ -595,6 +621,16 @@ def app_command_bypass_author_permission_checks(self) -> bool:
"""Whether invocations of this command as an application command will bypass author permission checks."""
return self._initialiser.app_command_bypass_author_permission_checks

@property
def name_localizations(self) -> t.Mapping[t.Union[hikari.Locale, str], str]:
"""A mapping of locale to localizations for this command"""
return self._initialiser.name_localizations

@property
def description_localizations(self) -> t.Mapping[t.Union[hikari.Locale, str], str]:
"""A mapping of locale to description localizations for this command"""
return self._initialiser.description_localizations

def __hash__(self) -> int:
return hash(self.name)

Expand Down Expand Up @@ -788,6 +824,12 @@ async def create(self, guild: t.Optional[int] = None) -> hikari.PartialCommand:
if self.app_command_default_member_permissions is not None:
kwargs["default_member_permissions"] = self.app_command_default_member_permissions

if self.name_localizations:
kwargs["name_localizations"] = self.name_localizations

if self.description_localizations:
kwargs["description_localizations"] = self.description_localizations

cmd_type: hikari.CommandType = kwargs.pop("type")
created_cmd: hikari.PartialCommand
if cmd_type is hikari.CommandType.SLASH:
Expand Down
6 changes: 6 additions & 0 deletions lightbulb/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ def command(
inherit_checks (:obj:`bool`): Whether or not the command should inherit checks from the parent group. Only
affects subcommands. Defaults to ``False``.
pass_options (:obj:`bool`): Whether the command will have its options passed as keyword arguments when invoked.
name_localizations (Mapping[Union[:obj:`hikari.locales.Locale`, :obj:`str`], :obj:`str`]): A mapping of locale to name localizations for this command. Defaults to an empty dictionary.
description_localizations (Mapping[Union[:obj:`hikari.locales.Locale`, :obj:`str`], :obj:`str`]): A mapping of locale to description localizations for this command. Defaults to an empty dictionary.
cls (Type[:obj:`~.commands.base.CommandLike`]): ``CommandLike`` class to instantiate from this decorator.
Defaults to :obj:`~.commands.base.CommandLike`.
.. versionadded:: 2.1.0
``cls`` kwarg.
.. versionadded:: 2.2.1
``pass_options`` kwarg.
.. versionadded:: 2.3.0
``name_localizations`` and ``description_localizations`` kwargs.
"""

def decorate(func: CommandCallbackT) -> commands.base.CommandLike:
Expand Down Expand Up @@ -155,6 +159,8 @@ def option(
autocomplete (Union[:obj:`bool`, AutocompleteCallbackT]): Boolean representing whether the option will use
autocomplete or the callback to use for autocomplete for this option. This will only affect slash commands.
Defaults to ``False``.
name_localizations (Mapping[Union[:obj:`hikari.locales.Locale`, :obj:`str`], :obj:`str`]): A mapping of locale to name localizations for this option. Defaults to an empty dictionary.
description_localizations (Mapping[Union[:obj:`hikari.locales.Locale`, :obj:`str`], :obj:`str`]): A mapping of locale to description localizations for this option. Defaults to an empty dictionary.
cls (Type[:obj:`~.commands.base.OptionLike`]): ``OptionLike`` class to instantiate from this decorator. Defaults
to :obj:`~.commands.base.OptionLike`.
Expand Down

5 comments on commit 2ca2239

@PerchunPak
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, release?

@tandemdude
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PerchunPak it's really pissing me off that you keep telling me to release every time something is merged. I will release when the release is ready. Currently, I will not release until threads are properly supported. I really do not appreciate you telling me what to do.

@PerchunPak
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't want to annoy you.

I'm just waiting for the feature(s if count Python 3.11), and now it's even in repo and in production state, but I can't use it because it's not in PyPi.

@tandemdude
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you can use it, by installing it from the development branch using pip. A change doesn't need to be on pypi for you to be able to use it.

@PerchunPak
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know about it, but I would not stick to commit inside repo because (for example) dependabot doesn't support commits in dependency files (because of security problems).

This means, that some critical patches can (and more possibly that will) pass through me, as dependabot (and other tools, such as safety) will not notify me.

Please sign in to comment.