From c5f9e53d447cd627963a31507ec071836c9f9632 Mon Sep 17 00:00:00 2001 From: Jeong Arm Date: Mon, 12 Dec 2016 06:45:51 +0900 Subject: [PATCH] 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 --- AUTHORS.rst | 1 + telegram/ext/filters.py | 7 +++++++ tests/test_filters.py | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 9c33bc522..90267d60b 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -20,6 +20,7 @@ The following wonderful people contributed directly or indirectly to this projec - `jh0ker `_ - `JRoot3D `_ - `jlmadurga `_ +- `Kjwon15 `_ - `Li-aung Yip `_ - `macrojames `_ - `Michael Elovskikh `_ diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index c8ecd0336..c16db36cf 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -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): diff --git a/tests/test_filters.py b/tests/test_filters.py index 902a64cc1..1ef5e7db5 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -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))