Skip to content

Commit c5f9e53

Browse files
tribelajh0ker
authored andcommitted
Add "reply" filter (python-telegram-bot#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
1 parent acf1541 commit c5f9e53

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The following wonderful people contributed directly or indirectly to this projec
2020
- `jh0ker <https://github.com/jh0ker>`_
2121
- `JRoot3D <https://github.com/JRoot3D>`_
2222
- `jlmadurga <https://github.com/jlmadurga>`_
23+
- `Kjwon15 <https://github.com/kjwon15>`_
2324
- `Li-aung Yip <https://github.com/LiaungYip>`_
2425
- `macrojames <https://github.com/macrojames>`_
2526
- `Michael Elovskikh <https://github.com/wronglink>`_

telegram/ext/filters.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ class _Command(BaseFilter):
107107
def filter(self, message):
108108
return bool(message.text and message.text.startswith('/'))
109109

110+
class _Reply(BaseFilter):
111+
112+
def filter(self, message):
113+
return bool(message.reply_to_message)
114+
115+
reply = _Reply()
116+
110117
command = _Command()
111118

112119
class _Audio(BaseFilter):

tests/test_filters.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def test_filters_command(self):
5151
self.message.text = '/test'
5252
self.assertTrue(Filters.command(self.message))
5353

54+
def test_filters_reply(self):
55+
another_message = Message(1, User(1, "TestOther"), datetime.now(), Chat(0, 'private'))
56+
self.message.text = 'test'
57+
self.assertFalse(Filters.reply(self.message))
58+
self.assertFalse(Filters.reply(Filters.message))
59+
self.message.reply_to_message = another_message
60+
self.assertTrue(Filters.reply(self.message))
61+
5462
def test_filters_audio(self):
5563
self.message.audio = 'test'
5664
self.assertTrue(Filters.audio(self.message))

0 commit comments

Comments
 (0)