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

Use ArgParse instead of having to regex the text. #204

Open
Ryanb58 opened this issue Dec 27, 2019 · 0 comments
Open

Use ArgParse instead of having to regex the text. #204

Ryanb58 opened this issue Dec 27, 2019 · 0 comments

Comments

@Ryanb58
Copy link

Ryanb58 commented Dec 27, 2019

In a local project I am using this library, but then utilizing ArgParse to get information from the command sent to the bot. This works well when your bot is more of a command based tool.

For example:

@listen_to("^!client payments (.+)")
@respond_to("client payments (.+)")
def client_payments(message, text):
    # Parse the arguments
    parser = ArgumentParser()
    parser.add_argument('--client-id', type=str, dest='client_id')
    parser.add_argument('--email', type=str, dest='email')
    parser.add_argument('--trans-id', type=str, dest='trans_id')
    parsed_args = parser.custom_parse(message, text)

This allows us to onboard new devs quicker and prevents Havok when someone commits the wrong regex that accepts one too many weird things.

Was wondering how anyone else felt about this?

One thing that would be even cooler is if this could be a decorator...

like...

@listen_to("^!client payments (.+)")
@respond_to("client payments (.+)")
@arg('--client-id', type=str, dest='client_id')
@arg('--email', type=str, dest='email'')
@arg('--trans-id', type=str, dest='trans_id')
def client_payments(message, client_id, email, trans_id):
    pass

Anyone have any thoughts or opinions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant