discord_reargparse
Provides support for RegEx based argument parsing in commands for the discord.py library.
param_converter = RegExArgConverter(
r"^(\S+[\ \S]*?)(?:\ -c(\d+))?(\ -n)?$",
# OR re.compile(r"^(\S+[\ \S]*?)(?:\ -c(\d+))?(\ -n)?$"),
string = Parameter(
default="hello!",
),
count = Parameter(
int,
default=2,
),
new_line = Parameter(
lambda x: bool(x),
)
)
# ...
@bot.command()
async def repeat(ctx, *, params:param_converter=param_converter.defaults):
string = params["string"]
count = params["count"]
sep = "\n" if params.get("new_line", False) else " "
await ctx.send(sep.join([string]*count))
@repeat.error
async def repeat_error(ctx, error):
if isinstance(error, NotMatchedWithPattern):
await ctx.send(
"{0} not matched with pattern r'{1}'".format(
repr(error.argstr), error.pattern.pattern,
)
)
On your discord server, the commands can be invoked like this:
!repeat
> hello! hello!
!repeat Hi -c3 -n
> Hi
> Hi
> Hi
!repeat hello
world
→ will raise a NotMatchedWithPattern exception
Installation
Installation is available via pip:
pip install discord_reargparse
Documentation
Initialize an RegExArgConverter as in the example above, annotate a
keyword-only function argument in your command with the instance and,
optionally, set its default value by using the .defaults attribute.
Setting a default value can be omitted for non-optional regex groups.
It will raise a NotMatchedWithPattern exception if not matched
with given regex pattern.
Inside the command, you can access the arguments as a dict.
command's usage
The usage string of repeat command is displayed like.
!help repeat
> repeat [params=Args(r'^(\S+[\ \S]*?)(?:\ -c(\d+))?(\ -n)?$' => [string=hello!] [count=2] <new_line>)]
You might also want to set the usage parameter of the command() function
decorator to display a alternative usage string, especially when using the
RegExArgConverter.defaults attribute.
Metadata
Release files for discord-reargparse 0.0.1
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 |
|---|---|---|---|---|
| discord-reargparse-0.0.1.tar.gz | 5.4 kB | Without provenance | Details for discord-reargparse-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| discord_reargparse-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for discord_reargparse-0.0.1-py3-none-any.whl |
Total release size: 11.8 kB
Release files / discord-reargparse-0.0.1.tar.gz
| Download URL | discord-reargparse-0.0.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e4b91179925dd8562093c83582b4fae98007b2865da5cc37f5c9b6edeb7ca75
|
|
BLAKE2b-256 checksum How to use checksums |
5e1839476cff1d009573464ac66343040b2d0ba3129cd0993ce7f27b9eab18e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.8.3 Linux/5.4.44-1-MANJARO
|
Release files / discord_reargparse-0.0.1-py3-none-any.whl
| Download URL | discord_reargparse-0.0.1-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f105adc4e685ac18524fa0a24f4037b104777bb6a34c1c9b24648dc82d3e6713
|
|
BLAKE2b-256 checksum How to use checksums |
af74b6f508e171701a9bdd47932e59cb2ed233dc0a608d29a621e99ac720e0d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.8.3 Linux/5.4.44-1-MANJARO
|
Security for discord-reargparse 0.0.1
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.