Add poll messages support to filters (#1673)

This commit is contained in:
Eana Hufwe 2020-01-27 04:57:48 +08:00 committed by Noam Meltzer
parent 62f514f068
commit d9d65cc2ac
3 changed files with 15 additions and 0 deletions

View file

@ -26,6 +26,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `d-qoi <https://github.com/d-qoi>`_
- `daimajia <https://github.com/daimajia>`_
- `Daniel Reed <https://github.com/nmlorg>`_
- `Eana Hufwe <https://github.com/blueset>`_
- `Ehsan Online <https://github.com/ehsanonline>`_
- `Eli Gao <https://github.com/eligao>`_
- `Emilio Molinari <https://github.com/xates>`_

View file

@ -956,6 +956,15 @@ officedocument.wordprocessingml.document")``-
passport_data = _PassportData()
"""Messages that contain a :class:`telegram.PassportData`"""
class _Poll(BaseFilter):
name = 'Filters.poll'
def filter(self, message):
return bool(message.poll)
poll = _Poll()
"""Messages that contain a :class:`telegram.Poll`."""
class language(BaseFilter):
"""Filters messages to only allow those which are from users with a certain language code.

View file

@ -599,6 +599,11 @@ class TestFilters(object):
update.message.passport_data = 'test'
assert Filters.passport_data(update)
def test_filters_poll(self, update):
assert not Filters.poll(update)
update.message.poll = 'test'
assert Filters.poll(update)
def test_language_filter_single(self, update):
update.message.from_user.language_code = 'en_US'
assert (Filters.language('en_US'))(update)