mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +01:00
Add "reply" filter (#465)
* Add "reply" filter This filter will filter messages that reply to other's message. * Add test for "reply" filter * Add "Kjwon15" to AUTHORS.rst
This commit is contained in:
parent
acf1541395
commit
c5f9e53d44
3 changed files with 16 additions and 0 deletions
|
@ -20,6 +20,7 @@ The following wonderful people contributed directly or indirectly to this projec
|
|||
- `jh0ker <https://github.com/jh0ker>`_
|
||||
- `JRoot3D <https://github.com/JRoot3D>`_
|
||||
- `jlmadurga <https://github.com/jlmadurga>`_
|
||||
- `Kjwon15 <https://github.com/kjwon15>`_
|
||||
- `Li-aung Yip <https://github.com/LiaungYip>`_
|
||||
- `macrojames <https://github.com/macrojames>`_
|
||||
- `Michael Elovskikh <https://github.com/wronglink>`_
|
||||
|
|
|
@ -107,6 +107,13 @@ class Filters(object):
|
|||
def filter(self, message):
|
||||
return bool(message.text and message.text.startswith('/'))
|
||||
|
||||
class _Reply(BaseFilter):
|
||||
|
||||
def filter(self, message):
|
||||
return bool(message.reply_to_message)
|
||||
|
||||
reply = _Reply()
|
||||
|
||||
command = _Command()
|
||||
|
||||
class _Audio(BaseFilter):
|
||||
|
|
|
@ -51,6 +51,14 @@ class FiltersTest(BaseTest, unittest.TestCase):
|
|||
self.message.text = '/test'
|
||||
self.assertTrue(Filters.command(self.message))
|
||||
|
||||
def test_filters_reply(self):
|
||||
another_message = Message(1, User(1, "TestOther"), datetime.now(), Chat(0, 'private'))
|
||||
self.message.text = 'test'
|
||||
self.assertFalse(Filters.reply(self.message))
|
||||
self.assertFalse(Filters.reply(Filters.message))
|
||||
self.message.reply_to_message = another_message
|
||||
self.assertTrue(Filters.reply(self.message))
|
||||
|
||||
def test_filters_audio(self):
|
||||
self.message.audio = 'test'
|
||||
self.assertTrue(Filters.audio(self.message))
|
||||
|
|
Loading…
Reference in a new issue