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

Conversation

Projects
None yet
3 participants
@jossalgon
Contributor

jossalgon commented Feb 28, 2017

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

This comment has been minimized.

Show comment
Hide comment
@Eldinnie

Eldinnie Feb 28, 2017

Member

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

Member

Eldinnie commented Feb 28, 2017

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

@jossalgon

This comment has been minimized.

Show comment
Hide comment
@jossalgon

jossalgon Feb 28, 2017

Contributor

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.

Contributor

jossalgon commented Feb 28, 2017

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

This comment has been minimized.

Show comment
Hide comment
@jh0ker

jh0ker Feb 28, 2017

Member

@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 👍

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

This comment has been minimized.

Show comment
Hide comment
@jossalgon

jossalgon Feb 28, 2017

Contributor

Are the tests ok in this way?

Contributor

jossalgon commented Feb 28, 2017

Are the tests ok in this way?

@jh0ker

This comment has been minimized.

Show comment
Hide comment
@jh0ker

jh0ker Feb 28, 2017

Member

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

Member

jh0ker commented Feb 28, 2017

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

@jossalgon

This comment has been minimized.

Show comment
Hide comment
@jossalgon

jossalgon Feb 28, 2017

Contributor

👍 sorry, the commit is now amended

Contributor

jossalgon commented Feb 28, 2017

👍 sorry, the commit is now amended

@jh0ker

This comment has been minimized.

Show comment
Hide comment
@jh0ker

jh0ker Feb 28, 2017

Member

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?

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

This comment has been minimized.

Show comment
Hide comment
@jossalgon

jossalgon Feb 28, 2017

Contributor

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

Contributor

jossalgon commented Feb 28, 2017

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

@Eldinnie

This comment has been minimized.

Show comment
Hide comment
@Eldinnie

Eldinnie Feb 28, 2017

Member

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

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

This comment has been minimized.

Show comment
Hide comment
@jh0ker

jh0ker Feb 28, 2017

Member

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

Member

jh0ker commented Feb 28, 2017

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

@jh0ker

This comment has been minimized.

Show comment
Hide comment
@jh0ker

jh0ker Feb 28, 2017

Member

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

Member

jh0ker commented Feb 28, 2017

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

@jh0ker jh0ker merged commit e78d11a into python-telegram-bot:master Feb 28, 2017

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment