Skip to main content

A Typehint based flags system for discord.py

Project description

Typed Flags

A Typehint based system for including flag input in your discord.py commands.

Why bother with numerous decorators and patched commands when you just typehint your input to receive command flags?

Examples


Usage is as simple as typehinting the entire input argument string to TypedFlags, this in turn will convert everything and will return this argument as a dict of key:value pairs where each key is the flag, and the value is the value for that flag

from typed_flags import TypedFlags

@bot.command()
async def test(ctx, *, args: TypedFlags):
    # Send all of command args
    await ctx.send(args)

An example calling the above code: %test this "Lol ez" --try:=test string --hard:=This is kinda cool

args = {None: ['this', 'Lol ez'], 'try': 'test string', 'hard': 'This is kinda cool'}

A further example: %test --try:=test string --hard:=lol This is kinda cool

args = {'try': 'test string', 'hard': 'lol This is kinda cool'}

Note: Since we have no argless arguments, it is not in the returned data

Customization


You can customize two things, the string to preceed any flag values as well as the string to split up between the flag and its value. Both of these are keyword arguments when initializing TypedFlags

  • start: str -> The string to preceed any flags (Defaults to --)
  • delim: str -> What to split flags with to get the key:value split (Defaults to :=)

You do not have to provide these values. There are defaults in place. It is only for customization purposes

Important Notes


This package works in-line with how discord.py handles command parsing and consumption. That is to say the argument Hello world will be two variables, where as the argument "Hello world" will be parsed as one argument. This is something important to understand otherwise you will experience unexpected behaviour.

However, this only applies to 'flagless' arguments. Values between flags are considered to be all part of said flag (See examples)


Any arguments not associated with a flag will be added to the dictionary under the key None. The value for this key is a list containing all of the arguments found that do not corrospond to a given flag.

It is also important to note that if no flagless values are detected then this key will not be in the dictionary. You should check for this in your code.


Any arguments in argless are ordered according to the order they were received.

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

discord-typed-flags-1.1.3.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

discord_typed_flags-1.1.3-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file discord-typed-flags-1.1.3.tar.gz.

File metadata

  • Download URL: discord-typed-flags-1.1.3.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.5

File hashes

Hashes for discord-typed-flags-1.1.3.tar.gz
Algorithm Hash digest
SHA256 8a83309a30c517c79b4dc83f36ee5663ce22a73b4b690610f38888a8ea668355
MD5 c96ba69c7b1c8708ffe1fc7e8f13fcc1
BLAKE2b-256 da39c4e10f2eeabefe54dac67b6f1f7b4c874eac271f2211e1d971fae8d0d597

See more details on using hashes here.

Provenance

File details

Details for the file discord_typed_flags-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: discord_typed_flags-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.5

File hashes

Hashes for discord_typed_flags-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f551ac895fe921d5ecd7181b9a0d0754b25cb6e738b8dd8676f5a35f4edf70b4
MD5 19351007e5d205bcc333b7740fbee744
BLAKE2b-256 a63cd649936f854ec93dedf812338042ef719a61f1fc38ce4f0146f856f89f01

See more details on using hashes here.

Provenance

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