File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,33 @@ def status_update(message):
8585 def forwarded (message ):
8686 return bool (message .forward_date )
8787
88+ @staticmethod
89+ def entities (entity_types ):
90+ """Filters messages to only allow those which have a :class:`telegram.MessageEntity`
91+ that match `entity_types`.
92+
93+ Note:
94+ This filter functions as an OR filter, meaning that just one of the entity_type.
95+ If you want AND filtering instead, you have to specify multiple of this filter in the
96+ `filters` attribute. Example:
97+
98+ >>> MessageHandler([Filters.entities(TEXT_MENTION, MENTION),
99+ ... Filters.entities(HASHTAG)], callback)
100+
101+ Will require either a one type of mention AND a hashtag in the message.
102+
103+ Args:
104+ entity_types: List of entity types to check for. All types can be found as constants
105+ in :class:`telegram.MessageEntity`.
106+
107+ Returns: function to use as filter
108+ """
109+
110+ def entities_filter (message ):
111+ return any ([entity_types in entity .type for entity in message .entities ])
112+
113+ return entities_filter
114+
88115
89116class MessageHandler (Handler ):
90117 """
You can’t perform that action at this time.
0 commit comments