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

Add filters to commandHandler #536

Merged
merged 3 commits into from
Feb 28, 2017
Merged

Conversation

jossalgon
Copy link
Contributor

Add filters to CommandHandler.

Now you can filter commands, for example to separate a command from group and private or any filter you want.

updater = Updater(token=TG_TOKEN)
dp = updater.dispatcher

dp.add_handler(CommandHandler('start', start, filter_example))

where filter_example is:

def filter_example(msg):
    return msg.chat.type == 'private'

or

updater = Updater(token=TG_TOKEN)
dp = updater.dispatcher

dp.add_handler(CommandHandler('start', start, lambda msg: msg.chat.type == 'private'))

@Eldinnie
Copy link
Member

I'm looking forward to this, but I think you will have to write some tests for this to get it pulled.

@jossalgon
Copy link
Contributor Author

Do you mean a test on test_updater.py? like:
https://github.com/python-telegram-bot/python-telegram-bot/blob/master/tests/test_updater.py#L169-L185

I didn't find any more tests of commandHandler, thanks for the feedback.

@jh0ker
Copy link
Member

jh0ker commented Feb 28, 2017

@jossalgon Yes, indeed. Just add one test case where the filter allows the message and one test case where it doesn't, then we're good to merge I think 👍

@jossalgon
Copy link
Contributor Author

Are the tests ok in this way?

@jh0ker
Copy link
Member

jh0ker commented Feb 28, 2017

Great, but the name of the two test functions says MessageHandler, not CommandHandler ^^

@jossalgon
Copy link
Contributor Author

👍 sorry, the commit is now amended

@jh0ker
Copy link
Member

jh0ker commented Feb 28, 2017

I'll let the tests run through on Travis before merging, but it looks good. Thank you very much for your contribution :) Did you already add yourself to AUTHORS.rst?

@jossalgon
Copy link
Contributor Author

Not yet, I'll add a commit with that and it's a pleasure to collaborate :)

@Eldinnie
Copy link
Member

Eldinnie commented Feb 28, 2017

Would you mind adding me to authors to? I forgot and to make a single PR just for that :D
Pieter Schutz github.com/eldinnie

@jh0ker
Copy link
Member

jh0ker commented Feb 28, 2017

@Eldinnie I can just commit that directly to master, no need to piggyback it here @jossalgon ^^

@jh0ker
Copy link
Member

jh0ker commented Feb 28, 2017

anyways, tests look good so I'll merge now!

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

Successfully merging this pull request may close these issues.

None yet

3 participants