Add filters.PAID_MEDIA (#4357)

This commit is contained in:
Harshil 2024-07-07 16:23:31 -04:00 committed by GitHub
parent dba7866aab
commit 52237cf00c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View file

@ -58,6 +58,7 @@ __all__ = (
"IS_FROM_OFFLINE", "IS_FROM_OFFLINE",
"IS_TOPIC_MESSAGE", "IS_TOPIC_MESSAGE",
"LOCATION", "LOCATION",
"PAID_MEDIA",
"PASSPORT_DATA", "PASSPORT_DATA",
"PHOTO", "PHOTO",
"POLL", "POLL",
@ -1706,6 +1707,20 @@ class Mention(MessageFilter):
return any(self._check_mention(message, mention) for mention in self._mentions) 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): class _PassportData(MessageFilter):
__slots__ = () __slots__ = ()

View file

@ -902,6 +902,11 @@ class TestFilters:
update.message.story = "test" update.message.story = "test"
assert filters.STORY.check_update(update) 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): def test_filters_video(self, update):
assert not filters.VIDEO.check_update(update) assert not filters.VIDEO.check_update(update)
update.message.video = "test" update.message.video = "test"