Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options and flags to command filter #552

Open
wants to merge 2 commits into
base: master
from

Conversation

@alemigliardi
Copy link

@alemigliardi alemigliardi commented Nov 27, 2020

I added a way to define options and flags to look for in the command text. Having just a list of words wasn't enough for complex commands.

I made it keep the old message.command list for compatibility, but having it as one dict would be nicer in my opinion.

Basically, now you can do

@bot.on_message(filters.command(["somecmd"], ["."], options={
    "opt1" : ["-o", "-option"],
    "opt2" : ["-p", "-ption"]
}, flags=["-list", "-random"]))
async def my_cmd(client, message):
  if "opt1" in message.opts:
    somevalue = int(message.opts["opt1"]
  if "-list" in message.opts["flags"]:
    # do something else
Added options and flags. Options will consume both keyword and value right next to, flags will just consume the keyword itself.

`message.command` is now a dict : the "old" list can be found in `message.command["raw"]`. Options, if found, will be inserted in the dict with the name they were registered with. Flags will be added to a list in `message.command["flags"]`. The remaining command can be accessed as a list in `message.command["cmd"]` or as one joined string in `message.command["arg"]`. Note that neither of these will be present if options and flags will consume the command list completely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant
You can’t perform that action at this time.