-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Add a caption_entity filter for filtering caption entities #1068
Conversation
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. |
This would be really helpful. Code looks good aswell. +1 |
telegram/ext/filters.py
Outdated
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]) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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) |
There was a problem hiding this comment.
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 😄
Thanks for your contribution 🙂 |
Currently, the Filters.entity filter only checks message.entities.
This PR adds Filters.caption_entities to check message.caption_entities.