diff --git a/telegram/ext/filters.py b/telegram/ext/filters.py index 5147574e07a..8182ac64996 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"