Skip to content
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

Add a caption_entity filter for filtering caption entities #1068

Merged

Conversation

PaulSonOfLars
Copy link
Contributor

Currently, the Filters.entity filter only checks message.entities.
This PR adds Filters.caption_entities to check message.caption_entities.

@PaulSonOfLars
Copy link
Contributor Author

PaulSonOfLars commented Apr 8, 2018

I think it'd also be nice to have one filter for both entity types, but having trouble naming it; all_entity, any_entity, either_entity, both_entity all seem kinda misleading.

@keessonnema
Copy link

This would be really helpful. Code looks good aswell. +1

self.name = 'Filters.caption_entity({})'.format(self.entity_type)

def filter(self, message):
return any([entity.type == self.entity_type for entity in message.caption_entities])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, but why not just use a generator expression instead of a list comprehension?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally agree, i copy pasted the previous filter code is why

Copy link
Member

@jh0ker jh0ker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@@ -532,7 +532,28 @@ def __init__(self, entity_type):
self.name = 'Filters.entity({})'.format(self.entity_type)

def filter(self, message):
return any([entity.type == self.entity_type for entity in message.entities])
return any(entity.type == self.entity_type for entity in message.entities)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this too 😄

@jh0ker jh0ker merged commit b5196f0 into python-telegram-bot:master Apr 20, 2018
@jh0ker
Copy link
Member

jh0ker commented Apr 20, 2018

Thanks for your contribution 🙂

@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants