From 34149364001901f067c44ae41321fa9e79e9db53 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Sun, 7 Jul 2024 15:15:48 -0400 Subject: [PATCH 1/2] Add PAID_MEDIA filter --- telegram/ext/filters.py | 15 +++++++++++++++ tests/ext/test_filters.py | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index 5147574e07a..dd6d58477a2 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -58,6 +58,7 @@ "IS_FROM_OFFLINE", "IS_TOPIC_MESSAGE", "LOCATION", + "PAID_MEDIA", "PASSPORT_DATA", "PHOTO", "POLL", @@ -1706,6 +1707,20 @@ def filter(self, message: Message) -> bool: return any(self._check_mention(message, mention) for mention in self._mentions) +class _PaidMedia(MessageFilter): + __slots__ = () + + def filter(self, message: Message) -> bool: + return bool(message.paid_media) + + +PAID_MEDIA = _PaidMedia(name="filters.PAID_MEDIA") +"""Messages that contain :attr:`telegram.Message.paid_media`. + + .. versionadded:: NEXT.VERSION +""" + + class _PassportData(MessageFilter): __slots__ = () diff --git a/tests/ext/test_filters.py b/tests/ext/test_filters.py index 97d17e2ebaf..cc237f41001 100644 --- a/tests/ext/test_filters.py +++ b/tests/ext/test_filters.py @@ -902,6 +902,11 @@ def test_filters_story(self, update): update.message.story = "test" assert filters.STORY.check_update(update) + def test_filters_paid_media(self, update): + assert not filters.PAID_MEDIA.check_update(update) + update.message.paid_media = "test" + assert filters.PAID_MEDIA.check_update(update) + def test_filters_video(self, update): assert not filters.VIDEO.check_update(update) update.message.video = "test" From 568c8b5677bb2ceeec93eeb1de7c2af96b47da83 Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Sun, 7 Jul 2024 15:17:35 -0400 Subject: [PATCH 2/2] indentation --- telegram/ext/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index dd6d58477a2..8182ac64996 100644 --- a/telegram/ext/filters.py +++ b/telegram/ext/filters.py @@ -1717,7 +1717,7 @@ def filter(self, message: Message) -> bool: PAID_MEDIA = _PaidMedia(name="filters.PAID_MEDIA") """Messages that contain :attr:`telegram.Message.paid_media`. - .. versionadded:: NEXT.VERSION +.. versionadded:: NEXT.VERSION """