Skip to content

Add a caption_entity filter for filtering caption entities - #1068

Merged
jh0ker merged 2 commits into
python-telegram-bot:masterfrom
PaulSonOfLars:care_about_caption_entities
Apr 20, 2018
Merged

Add a caption_entity filter for filtering caption entities#1068
jh0ker merged 2 commits into
python-telegram-bot:masterfrom
PaulSonOfLars:care_about_caption_entities

Conversation

@PaulSonOfLars

Copy link
Copy Markdown
Contributor

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

@PaulSonOfLars

PaulSonOfLars commented Apr 8, 2018

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown

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

Comment thread 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])

Copy link
Copy Markdown
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
Copy Markdown
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

@jh0ker jh0ker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍

Comment thread telegram/ext/filters.py

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
Copy Markdown
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

jh0ker commented Apr 20, 2018

Copy link
Copy Markdown
Member

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.

3 participants