tanchi
A signature parser for hikari's command handler tanjun.
Finally be able to define your commands without those bloody decorator chains!
Example
@component.with_slash_command
@tanchi.as_slash_command(default_to_ephemeral=True)
async def command(
ctx: tanjun.abc.SlashContext,
integer: int = 0,
flag: bool = False,
channel: typing.Optional[hikari.GuildTextChannel] = None,
):
"""Small tanchi command
Parameters
----------
integer : int
Any integer value.
flag : bool
Whether this flag should be enabled.
channel : hikari.GuildTextChannel
The channel to target.
"""
Documentation?
Ordinary Types
All builtin types supported in slash commands (str, int, float, bool) do not need any special care.
option: str
Choices
Choices can either be made with typing.Literal or enum.Enum
option: typing.Literal["Foo", "Bar", "Baz"]
class MyEnum(enum.IntEnum):
foo = 1
bar = 2
baz = 3
option: MyEnum
Ranges
Integer and float options support min and max boundaries. These can be set with tanchi.Range.
The type of the option is discerned from the boundaries.
int_option: tanchi.Range[1, 10]
float_option: tanchi.Range[0.0, 1.0]
Channels
Channels types may be enforced with the help of typing.Union. If you want all channel types use hikari.GuildChannel
option: typing.Union[hikari.GuildTextChannel, hikari.GuildNewsChannel]
Converters
Types are implicitly converted if a builtin tanjun converter is available.
option: hikari.Emoji
To provide your own converter you can use tanchi.Converted.
option: tanchi.Converted[int, round]
Autocomplete
Instead of using a decorator, autocompleters can be provided directly in the annotation with tanchi.Autocompleted.
option: tanchi.Autocompleted[autocomplete_callback]
Since converters and autocompletion are often used together you can provide a converter directly.
option: tanchi.Autocompleted[autocomplete_callback, converter_callback]
MyPy compatibility
Because mypy does not respect __class_getitem__ you'll most likely have to use typing.Annotated for some cases.
option: typing.Annotated[int, tanchi.Range(1, 10)]
option: typing.Annotated[int, tanchi.Converted(range)]
option: typing.Annotated[str, tanchi.Autocompleted(autocomplete_callback)]
Docstrings
Tanchi parses descriptions from docstrings.
Examples of all supported formats:
ReST
"""Command description on a single line
Parameters
----------
foo : OptionType
Description for the option named "foo"
bar:
Description for the option named "bar"
"""
"""Command description on a single line
Args:
foo (OptionType): Description for the option named "foo"
bar: Description for the option named "bar"
"""
Autocompletion Examples
Instead of using context.set_choices you can choose to return options as either a sequence or a mapping.
@tanchi.as_slash_command()
async def command(context: tanjun.abc.SlashContext, option: str) -> None:
...
@tanchi.with_autocomplete(command, "option")
def autocomplete_names(context: tanjun.abc.AutocompleteContext, option: str):
return [word for word in WORDS if option.lower() in word.lower()]
Returning the options is also supported inside Autocompleted
Metadata
Release files for hikari-tanchi 1.3.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hikari-tanchi-1.3.6.tar.gz | 9.7 kB | Without provenance | Details for hikari-tanchi-1.3.6.tar.gz |
Release files / hikari-tanchi-1.3.6.tar.gz
| Download URL | hikari-tanchi-1.3.6.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64549c4d7a9ba7406159df91743f1c64faea3fc357c45ae68e719938ef759589
|
|
BLAKE2b-256 checksum How to use checksums |
3816be157fe46cd5d58c0d2103bd987d06d9e64bd5e323005afad2f496061ac9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.26.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.6
|
Security for hikari-tanchi 1.3.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.