Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add filters.PAID_MEDIA #4357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions telegram/ext/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"IS_FROM_OFFLINE",
"IS_TOPIC_MESSAGE",
"LOCATION",
"PAID_MEDIA",
"PASSPORT_DATA",
"PHOTO",
"POLL",
Expand Down Expand Up @@ -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__ = ()

Expand Down
5 changes: 5 additions & 0 deletions tests/ext/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading