Skip to main content

A signature parser for hikari's command handler tanjun.

Project description

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
        Int value.
    flag : bool
        Whether this flag should be enabled
    channel : hikari.GuildTextChannel
        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]

Because mypy does not respect __class_getitem__ you'll most likely have to use typing.Annotated

option: typing.Annotated[int, tanchi.Range(1, 10)]

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]

Because mypy does not respect __class_getitem__ you'll most likely have to use typing.Annotated

option: typing.Annotated[int, tanchi.Converted(range)]

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"
"""

Google

"""Command description on a single line

Args:
    foo (OptionType): Description for the option named "foo"
    bar: Description for the option named "bar"
"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hikari-tanchi-1.2.tar.gz (7.6 kB view details)

Uploaded Source

File details

Details for the file hikari-tanchi-1.2.tar.gz.

File metadata

  • Download URL: hikari-tanchi-1.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using 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.61.1 CPython/3.9.6

File hashes

Hashes for hikari-tanchi-1.2.tar.gz
Algorithm Hash digest
SHA256 bd820498b44df52e40fce3f8b5f40f37da3076fc0d1d906e84c3a95812b4c586
MD5 cf20b779e43e8bf6ac872bab18f760c6
BLAKE2b-256 5e153dc924cc67fbc79282fb4ee6a5a05d3a7a641fa6067faf88748b2a9089f1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page