2016-09-14 19:29:15 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# A library that provides a Python interface to the Telegram Bot API
|
2018-01-04 16:16:06 +01:00
|
|
|
# Copyright (C) 2015-2018
|
2016-09-14 19:29:15 +02:00
|
|
|
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser Public License
|
|
|
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
2017-09-01 08:43:08 +02:00
|
|
|
"""This module contains the Filters for use with the MessageHandler class."""
|
2018-03-15 05:59:27 +01:00
|
|
|
|
|
|
|
import re
|
2019-02-13 12:07:25 +01:00
|
|
|
|
2017-07-01 17:08:45 +02:00
|
|
|
from future.utils import string_types
|
2017-05-21 14:00:53 +02:00
|
|
|
|
2019-11-29 13:09:44 +01:00
|
|
|
from telegram import Chat, Update
|
2019-02-13 12:07:25 +01:00
|
|
|
|
2019-02-18 20:04:52 +01:00
|
|
|
__all__ = ['Filters', 'BaseFilter', 'InvertedFilter', 'MergedFilter']
|
|
|
|
|
2016-09-14 19:29:15 +02:00
|
|
|
|
|
|
|
class BaseFilter(object):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Base class for all Message Filters.
|
2016-09-25 00:30:04 +02:00
|
|
|
|
|
|
|
Subclassing from this class filters to be combined using bitwise operators:
|
|
|
|
|
|
|
|
And:
|
|
|
|
|
2016-10-14 10:32:12 +02:00
|
|
|
>>> (Filters.text & Filters.entity(MENTION))
|
2016-09-25 00:30:04 +02:00
|
|
|
|
|
|
|
Or:
|
|
|
|
|
|
|
|
>>> (Filters.audio | Filters.video)
|
|
|
|
|
2017-03-28 18:38:44 +02:00
|
|
|
Not:
|
|
|
|
|
|
|
|
>>> ~ Filters.command
|
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
Also works with more than two filters:
|
|
|
|
|
2016-10-14 10:32:12 +02:00
|
|
|
>>> (Filters.text & (Filters.entity(URL) | Filters.entity(TEXT_LINK)))
|
2017-03-28 18:38:44 +02:00
|
|
|
>>> Filters.text & (~ Filters.forwarded)
|
2016-09-25 00:30:04 +02:00
|
|
|
|
2019-03-14 09:03:21 +01:00
|
|
|
Note:
|
|
|
|
Filters use the same short circuiting logic that pythons `and`, `or` and `not`.
|
|
|
|
This means that for example:
|
|
|
|
|
|
|
|
>>> Filters.regex(r'(a?x)') | Filters.regex(r'(b?x)')
|
|
|
|
|
|
|
|
With a message.text of `x`, will only ever return the matches for the first filter,
|
|
|
|
since the second one is never evaluated.
|
|
|
|
|
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
If you want to create your own filters create a class inheriting from this class and implement
|
|
|
|
a `filter` method that returns a boolean: `True` if the message should be handled, `False`
|
|
|
|
otherwise. Note that the filters work only as class instances, not actual class objects
|
|
|
|
(so remember to initialize your filter classes).
|
2017-06-21 13:46:03 +02:00
|
|
|
|
|
|
|
By default the filters name (what will get printed when converted to a string for display)
|
|
|
|
will be the class name. If you want to overwrite this assign a better name to the `name`
|
|
|
|
class variable.
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
Attributes:
|
|
|
|
name (:obj:`str`): Name for this filter. Defaults to the type of filter.
|
2019-02-13 12:07:25 +01:00
|
|
|
update_filter (:obj:`bool`): Whether this filter should work on update. If ``False`` it
|
|
|
|
will run the filter on :attr:`update.effective_message``. Default is ``False``.
|
|
|
|
data_filter (:obj:`bool`): Whether this filter is a data filter. A data filter should
|
|
|
|
return a dict with lists. The dict will be merged with
|
|
|
|
:class:`telegram.ext.CallbackContext`'s internal dict in most cases
|
|
|
|
(depends on the handler).
|
2016-09-25 00:30:04 +02:00
|
|
|
"""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
name = None
|
2019-02-13 12:07:25 +01:00
|
|
|
update_filter = False
|
|
|
|
data_filter = False
|
2017-06-18 15:28:48 +02:00
|
|
|
|
2019-02-13 12:07:25 +01:00
|
|
|
def __call__(self, update):
|
|
|
|
if self.update_filter:
|
|
|
|
return self.filter(update)
|
|
|
|
else:
|
|
|
|
return self.filter(update.effective_message)
|
2016-09-14 19:29:15 +02:00
|
|
|
|
|
|
|
def __and__(self, other):
|
|
|
|
return MergedFilter(self, and_filter=other)
|
|
|
|
|
|
|
|
def __or__(self, other):
|
|
|
|
return MergedFilter(self, or_filter=other)
|
|
|
|
|
2017-03-28 18:38:44 +02:00
|
|
|
def __invert__(self):
|
|
|
|
return InvertedFilter(self)
|
|
|
|
|
2017-06-20 21:41:23 +02:00
|
|
|
def __repr__(self):
|
2017-06-21 13:46:03 +02:00
|
|
|
# We do this here instead of in a __init__ so filter don't have to call __init__ or super()
|
|
|
|
if self.name is None:
|
2017-06-18 15:28:48 +02:00
|
|
|
self.name = self.__class__.__name__
|
|
|
|
return self.name
|
|
|
|
|
2019-02-13 12:07:25 +01:00
|
|
|
def filter(self, update):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""This method must be overwritten.
|
2017-07-23 22:33:08 +02:00
|
|
|
|
2019-02-13 12:07:25 +01:00
|
|
|
Note:
|
|
|
|
If :attr:`update_filter` is false then the first argument is `message` and of
|
|
|
|
type :class:`telegram.Message`.
|
|
|
|
|
2017-07-23 22:33:08 +02:00
|
|
|
Args:
|
2019-02-13 12:07:25 +01:00
|
|
|
update (:class:`telegram.Update`): The update that is tested.
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
Returns:
|
2019-02-13 12:07:25 +01:00
|
|
|
:obj:`dict` or :obj:`bool`
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2017-07-23 22:33:08 +02:00
|
|
|
"""
|
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2017-03-28 18:38:44 +02:00
|
|
|
class InvertedFilter(BaseFilter):
|
|
|
|
"""Represents a filter that has been inverted.
|
|
|
|
|
|
|
|
Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
f: The filter to invert.
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2017-03-28 18:38:44 +02:00
|
|
|
"""
|
2019-02-13 12:07:25 +01:00
|
|
|
update_filter = True
|
2017-03-28 18:38:44 +02:00
|
|
|
|
|
|
|
def __init__(self, f):
|
|
|
|
self.f = f
|
|
|
|
|
2019-02-13 12:07:25 +01:00
|
|
|
def filter(self, update):
|
|
|
|
return not bool(self.f(update))
|
2017-03-28 18:38:44 +02:00
|
|
|
|
2017-06-20 21:41:23 +02:00
|
|
|
def __repr__(self):
|
2017-06-18 15:28:48 +02:00
|
|
|
return "<inverted {}>".format(self.f)
|
2017-03-28 18:38:44 +02:00
|
|
|
|
|
|
|
|
2016-09-14 19:29:15 +02:00
|
|
|
class MergedFilter(BaseFilter):
|
2016-10-14 10:32:12 +02:00
|
|
|
"""Represents a filter consisting of two other filters.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
base_filter: Filter 1 of the merged filter
|
|
|
|
and_filter: Optional filter to "and" with base_filter. Mutually exclusive with or_filter.
|
|
|
|
or_filter: Optional filter to "or" with base_filter. Mutually exclusive with and_filter.
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2016-10-14 10:32:12 +02:00
|
|
|
"""
|
2019-02-13 12:07:25 +01:00
|
|
|
update_filter = True
|
2016-09-14 19:29:15 +02:00
|
|
|
|
|
|
|
def __init__(self, base_filter, and_filter=None, or_filter=None):
|
|
|
|
self.base_filter = base_filter
|
2019-02-13 12:07:25 +01:00
|
|
|
if self.base_filter.data_filter:
|
|
|
|
self.data_filter = True
|
2016-09-14 19:29:15 +02:00
|
|
|
self.and_filter = and_filter
|
2019-02-13 12:07:25 +01:00
|
|
|
if (self.and_filter
|
|
|
|
and not isinstance(self.and_filter, bool)
|
|
|
|
and self.and_filter.data_filter):
|
|
|
|
self.data_filter = True
|
2016-09-14 19:29:15 +02:00
|
|
|
self.or_filter = or_filter
|
2019-02-13 12:07:25 +01:00
|
|
|
if (self.or_filter
|
|
|
|
and not isinstance(self.and_filter, bool)
|
|
|
|
and self.or_filter.data_filter):
|
|
|
|
self.data_filter = True
|
|
|
|
|
|
|
|
def _merge(self, base_output, comp_output):
|
|
|
|
base = base_output if isinstance(base_output, dict) else {}
|
|
|
|
comp = comp_output if isinstance(comp_output, dict) else {}
|
|
|
|
for k in comp.keys():
|
|
|
|
# Make sure comp values are lists
|
|
|
|
comp_value = comp[k] if isinstance(comp[k], list) else []
|
|
|
|
try:
|
|
|
|
# If base is a list then merge
|
|
|
|
if isinstance(base[k], list):
|
|
|
|
base[k] += comp_value
|
|
|
|
else:
|
|
|
|
base[k] = [base[k]] + comp_value
|
|
|
|
except KeyError:
|
|
|
|
base[k] = comp_value
|
|
|
|
return base
|
|
|
|
|
|
|
|
def filter(self, update):
|
|
|
|
base_output = self.base_filter(update)
|
|
|
|
# We need to check if the filters are data filters and if so return the merged data.
|
|
|
|
# If it's not a data filter or an or_filter but no matches return bool
|
2016-09-14 19:29:15 +02:00
|
|
|
if self.and_filter:
|
2019-03-14 09:03:21 +01:00
|
|
|
# And filter needs to short circuit if base is falsey
|
|
|
|
if base_output:
|
|
|
|
comp_output = self.and_filter(update)
|
|
|
|
if comp_output:
|
|
|
|
if self.data_filter:
|
|
|
|
merged = self._merge(base_output, comp_output)
|
|
|
|
if merged:
|
|
|
|
return merged
|
|
|
|
return True
|
2016-09-14 19:29:15 +02:00
|
|
|
elif self.or_filter:
|
2019-03-14 09:03:21 +01:00
|
|
|
# Or filter needs to short circuit if base is truthey
|
|
|
|
if base_output:
|
2019-02-13 12:07:25 +01:00
|
|
|
if self.data_filter:
|
2019-03-14 09:03:21 +01:00
|
|
|
return base_output
|
2019-02-13 12:07:25 +01:00
|
|
|
return True
|
2019-03-14 09:03:21 +01:00
|
|
|
else:
|
|
|
|
comp_output = self.or_filter(update)
|
|
|
|
if comp_output:
|
|
|
|
if self.data_filter:
|
|
|
|
return comp_output
|
|
|
|
return True
|
2019-02-13 12:07:25 +01:00
|
|
|
return False
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2017-06-20 21:41:23 +02:00
|
|
|
def __repr__(self):
|
2017-06-18 15:28:48 +02:00
|
|
|
return "<{} {} {}>".format(self.base_filter, "and" if self.and_filter else "or",
|
|
|
|
self.and_filter or self.or_filter)
|
2016-09-25 16:31:06 +02:00
|
|
|
|
2016-09-14 19:29:15 +02:00
|
|
|
|
|
|
|
class Filters(object):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Predefined filters for use as the `filter` argument of :class:`telegram.ext.MessageHandler`.
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
Use ``MessageHandler(Filters.video, callback_method)`` to filter all video
|
|
|
|
messages. Use ``MessageHandler(Filters.contact, callback_method)`` for all contacts. etc.
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2016-09-14 19:29:15 +02:00
|
|
|
"""
|
|
|
|
|
2016-10-15 22:58:55 +02:00
|
|
|
class _All(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.all'
|
2016-10-15 22:58:55 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return True
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
all = _All()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""All Messages."""
|
2016-10-15 22:58:55 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Text(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.text'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2019-11-29 13:09:44 +01:00
|
|
|
class _TextIterable(BaseFilter):
|
|
|
|
|
|
|
|
def __init__(self, iterable):
|
|
|
|
self.iterable = iterable
|
|
|
|
self.name = 'Filters.text({})'.format(iterable)
|
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
if message.text and not message.text.startswith('/'):
|
|
|
|
return message.text in self.iterable
|
|
|
|
return False
|
|
|
|
|
|
|
|
def __call__(self, update):
|
|
|
|
if isinstance(update, Update):
|
|
|
|
if self.update_filter:
|
|
|
|
return self.filter(update)
|
|
|
|
else:
|
|
|
|
return self.filter(update.effective_message)
|
|
|
|
else:
|
|
|
|
return self._TextIterable(update)
|
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.text and not message.text.startswith('/'))
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
text = _Text()
|
2019-11-29 13:09:44 +01:00
|
|
|
"""Text Messages. If an iterable of strings is passed, it filters messages to only allow those
|
|
|
|
whose text is appearing in the given iterable.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
To allow any text message, simply use
|
|
|
|
``MessageHandler(Filters.text, callback_method)``.
|
|
|
|
|
|
|
|
A simple usecase for passing an iterable is to allow only messages that were send by a
|
|
|
|
custom :class:`telegram.ReplyKeyboardMarkup`::
|
|
|
|
|
|
|
|
buttons = ['Start', 'Settings', 'Back']
|
|
|
|
markup = ReplyKeyboardMarkup.from_column(buttons)
|
|
|
|
...
|
|
|
|
MessageHandler(Filters.text(buttons), callback_method)
|
|
|
|
|
|
|
|
Args:
|
|
|
|
update (Iterable[:obj:`str`], optional): Which messages to allow. Only exact matches
|
|
|
|
are allowed. If not specified, will allow any text message.
|
|
|
|
"""
|
|
|
|
|
|
|
|
class _Caption(BaseFilter):
|
|
|
|
name = 'Filters.caption'
|
|
|
|
|
|
|
|
class _CaptionIterable(BaseFilter):
|
|
|
|
|
|
|
|
def __init__(self, iterable):
|
|
|
|
self.iterable = iterable
|
|
|
|
self.name = 'Filters.caption({})'.format(iterable)
|
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
if message.caption:
|
|
|
|
return message.caption in self.iterable
|
|
|
|
return False
|
|
|
|
|
|
|
|
def __call__(self, update):
|
|
|
|
if isinstance(update, Update):
|
|
|
|
if self.update_filter:
|
|
|
|
return self.filter(update)
|
|
|
|
else:
|
|
|
|
return self.filter(update.effective_message)
|
|
|
|
else:
|
|
|
|
return self._CaptionIterable(update)
|
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.caption)
|
|
|
|
|
|
|
|
caption = _Caption()
|
|
|
|
"""Messages with a caption. If an iterable of strings is passed, it filters messages to only
|
|
|
|
allow those whose caption is appearing in the given iterable.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
``MessageHandler(Filters.caption, callback_method)``
|
|
|
|
|
|
|
|
Args:
|
|
|
|
update (Iterable[:obj:`str`], optional): Which captions to allow. Only exact matches
|
|
|
|
are allowed. If not specified, will allow any message with a caption.
|
|
|
|
"""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Command(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.command'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.text and message.text.startswith('/'))
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
command = _Command()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages starting with ``/``."""
|
2017-06-18 15:28:48 +02:00
|
|
|
|
2018-03-15 05:59:27 +01:00
|
|
|
class regex(BaseFilter):
|
|
|
|
"""
|
2019-02-08 11:12:49 +01:00
|
|
|
Filters updates by searching for an occurrence of ``pattern`` in the message text.
|
2018-03-15 05:59:27 +01:00
|
|
|
The ``re.search`` function is used to determine whether an update should be filtered.
|
2019-02-08 11:12:49 +01:00
|
|
|
|
2018-03-15 05:59:27 +01:00
|
|
|
Refer to the documentation of the ``re`` module for more information.
|
|
|
|
|
2019-02-13 12:07:25 +01:00
|
|
|
To get the groups and groupdict matched, see :attr:`telegram.ext.CallbackContext.matches`.
|
2018-03-15 05:59:27 +01:00
|
|
|
|
|
|
|
Examples:
|
2019-02-08 11:12:49 +01:00
|
|
|
Use ``MessageHandler(Filters.regex(r'help'), callback)`` to capture all messages that
|
|
|
|
contain the word help. You can also use
|
|
|
|
``MessageHandler(Filters.regex(re.compile(r'help', re.IGNORECASE), callback)`` if
|
|
|
|
you want your pattern to be case insensitive. This approach is recommended
|
|
|
|
if you need to specify flags on your pattern.
|
|
|
|
|
2019-03-14 09:03:21 +01:00
|
|
|
Note:
|
|
|
|
Filters use the same short circuiting logic that pythons `and`, `or` and `not`.
|
|
|
|
This means that for example:
|
|
|
|
|
|
|
|
>>> Filters.regex(r'(a?x)') | Filters.regex(r'(b?x)')
|
|
|
|
|
|
|
|
With a message.text of `x`, will only ever return the matches for the first filter,
|
|
|
|
since the second one is never evaluated.
|
|
|
|
|
2018-03-15 05:59:27 +01:00
|
|
|
Args:
|
|
|
|
pattern (:obj:`str` | :obj:`Pattern`): The regex pattern.
|
|
|
|
"""
|
|
|
|
|
2019-02-13 12:07:25 +01:00
|
|
|
data_filter = True
|
|
|
|
|
2018-03-15 05:59:27 +01:00
|
|
|
def __init__(self, pattern):
|
2019-02-08 11:12:49 +01:00
|
|
|
if isinstance(pattern, string_types):
|
|
|
|
pattern = re.compile(pattern)
|
|
|
|
self.pattern = pattern
|
2018-03-15 05:59:27 +01:00
|
|
|
self.name = 'Filters.regex({})'.format(self.pattern)
|
|
|
|
|
|
|
|
def filter(self, message):
|
2019-02-13 12:07:25 +01:00
|
|
|
"""""" # remove method from docs
|
2018-08-26 20:39:01 +02:00
|
|
|
if message.text:
|
2019-02-13 12:07:25 +01:00
|
|
|
match = self.pattern.search(message.text)
|
|
|
|
if match:
|
|
|
|
return {'matches': [match]}
|
|
|
|
return {}
|
2018-03-15 05:59:27 +01:00
|
|
|
|
2016-12-11 22:45:51 +01:00
|
|
|
class _Reply(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.reply'
|
2016-12-11 22:45:51 +01:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.reply_to_message)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
reply = _Reply()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that are a reply to another message."""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Audio(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.audio'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.audio)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
audio = _Audio()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.Audio`."""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Document(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.document'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2018-03-16 23:41:48 +01:00
|
|
|
class category(BaseFilter):
|
|
|
|
"""This Filter filters documents by their category in the mime-type attribute
|
|
|
|
|
|
|
|
Note:
|
|
|
|
This Filter only filters by the mime_type of the document,
|
|
|
|
it doesn't check the validity of the document.
|
|
|
|
The user can manipulate the mime-type of a message and
|
|
|
|
send media with wrong types that don't fit to this handler.
|
|
|
|
|
2019-02-18 20:04:52 +01:00
|
|
|
Example:
|
2018-03-16 23:41:48 +01:00
|
|
|
Filters.documents.category('audio/') returnes `True` for all types
|
|
|
|
of audio sent as file, for example 'audio/mpeg' or 'audio/x-wav'
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, category):
|
|
|
|
"""Initialize the category you want to filter
|
|
|
|
|
|
|
|
Args:
|
|
|
|
category (str, optional): category of the media you want to filter"""
|
|
|
|
self.category = category
|
|
|
|
self.name = "Filters.document.category('{}')".format(self.category)
|
|
|
|
|
|
|
|
def filter(self, message):
|
2019-02-13 12:07:25 +01:00
|
|
|
"""""" # remove method from docs
|
2018-03-16 23:41:48 +01:00
|
|
|
if message.document:
|
|
|
|
return message.document.mime_type.startswith(self.category)
|
|
|
|
|
|
|
|
application = category('application/')
|
|
|
|
audio = category('audio/')
|
|
|
|
image = category('image/')
|
|
|
|
video = category('video/')
|
|
|
|
text = category('text/')
|
|
|
|
|
|
|
|
class mime_type(BaseFilter):
|
|
|
|
"""This Filter filters documents by their mime-type attribute
|
|
|
|
|
|
|
|
Note:
|
|
|
|
This Filter only filters by the mime_type of the document,
|
|
|
|
it doesn't check the validity of document.
|
|
|
|
The user can manipulate the mime-type of a message and
|
|
|
|
send media with wrong types that don't fit to this handler.
|
|
|
|
|
2019-02-18 20:04:52 +01:00
|
|
|
Example:
|
|
|
|
``Filters.documents.mime_type('audio/mpeg')`` filters all audio in mp3 format.
|
2018-03-16 23:41:48 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, mimetype):
|
|
|
|
"""Initialize the category you want to filter
|
|
|
|
|
|
|
|
Args:
|
|
|
|
filetype (str, optional): mime_type of the media you want to filter"""
|
|
|
|
self.mimetype = mimetype
|
|
|
|
self.name = "Filters.document.mime_type('{}')".format(self.mimetype)
|
|
|
|
|
|
|
|
def filter(self, message):
|
2019-02-13 12:07:25 +01:00
|
|
|
"""""" # remove method from docs
|
2018-03-16 23:41:48 +01:00
|
|
|
if message.document:
|
|
|
|
return message.document.mime_type == self.mimetype
|
|
|
|
|
|
|
|
apk = mime_type('application/vnd.android.package-archive')
|
|
|
|
doc = mime_type('application/msword')
|
|
|
|
docx = mime_type('application/vnd.openxmlformats-officedocument.wordprocessingml.document')
|
|
|
|
exe = mime_type('application/x-ms-dos-executable')
|
|
|
|
gif = mime_type('video/mp4')
|
|
|
|
jpg = mime_type('image/jpeg')
|
|
|
|
mp3 = mime_type('audio/mpeg')
|
|
|
|
pdf = mime_type('application/pdf')
|
|
|
|
py = mime_type('text/x-python')
|
|
|
|
svg = mime_type('image/svg+xml')
|
|
|
|
txt = mime_type('text/plain')
|
|
|
|
targz = mime_type('application/x-compressed-tar')
|
|
|
|
wav = mime_type('audio/x-wav')
|
|
|
|
xml = mime_type('application/xml')
|
|
|
|
zip = mime_type('application/zip')
|
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.document)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
document = _Document()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""
|
|
|
|
Subset for messages containing a document/file.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Use these filters like: ``Filters.document.mp3``,
|
|
|
|
``Filters.document.mime_type("text/plain")`` etc. Or use just
|
|
|
|
``Filters.document`` for all document messages.
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
category: This Filter filters documents by their category in the mime-type attribute.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
``Filters.documents.category('audio/')`` filters all types
|
|
|
|
of audio sent as file, for example 'audio/mpeg' or 'audio/x-wav'. The following
|
|
|
|
attributes can be used as a shortcut like: ``Filters.document.audio``
|
|
|
|
|
|
|
|
application:
|
|
|
|
audio:
|
|
|
|
image:
|
|
|
|
video:
|
|
|
|
text:
|
|
|
|
mime_type: This Filter filters documents by their mime-type attribute.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
``Filters.documents.mime_type('audio/mpeg')`` filters all audio in mp3 format. The
|
|
|
|
following attributes can be used as a shortcut like: ``Filters.document.jpg``
|
|
|
|
apk:
|
|
|
|
doc:
|
|
|
|
docx:
|
|
|
|
exe:
|
|
|
|
gif:
|
|
|
|
jpg:
|
|
|
|
mp3:
|
|
|
|
pdf:
|
|
|
|
py:
|
|
|
|
svg:
|
|
|
|
txt:
|
|
|
|
targz:
|
|
|
|
wav:
|
|
|
|
xml:
|
|
|
|
zip:
|
|
|
|
category: This Filter filters documents by their category in the mime-type attribute
|
|
|
|
|
|
|
|
Note:
|
|
|
|
This Filter only filters by the mime_type of the document,
|
|
|
|
it doesn't check the validity of the document.
|
|
|
|
The user can manipulate the mime-type of a message and
|
|
|
|
send media with wrong types that don't fit to this handler.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
``Filters.documents.category('audio/')`` filters all types
|
|
|
|
of audio sent as file, for example 'audio/mpeg' or 'audio/x-wav'
|
|
|
|
application: Same as ``Filters.document.category("application")``.
|
|
|
|
audio: Same as ``Filters.document.category("audio")``.
|
|
|
|
image: Same as ``Filters.document.category("image")``.
|
|
|
|
video: Same as ``Filters.document.category("video")``.
|
|
|
|
text: Same as ``Filters.document.category("text")``.
|
|
|
|
mime_type: This Filter filters documents by their mime-type attribute
|
|
|
|
|
|
|
|
Note:
|
|
|
|
This Filter only filters by the mime_type of the document,
|
|
|
|
it doesn't check the validity of document.
|
|
|
|
|
|
|
|
The user can manipulate the mime-type of a message and
|
|
|
|
send media with wrong types that don't fit to this handler.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
``Filters.documents.mime_type('audio/mpeg')`` filters all audio in mp3 format.
|
|
|
|
apk: Same as ``Filters.document.mime_type("application/vnd.android.package-archive")``-
|
|
|
|
doc: Same as ``Filters.document.mime_type("application/msword")``-
|
|
|
|
docx: Same as ``Filters.document.mime_type("application/vnd.openxmlformats-\
|
|
|
|
officedocument.wordprocessingml.document")``-
|
|
|
|
exe: Same as ``Filters.document.mime_type("application/x-ms-dos-executable")``-
|
|
|
|
gif: Same as ``Filters.document.mime_type("video/mp4")``-
|
|
|
|
jpg: Same as ``Filters.document.mime_type("image/jpeg")``-
|
|
|
|
mp3: Same as ``Filters.document.mime_type("audio/mpeg")``-
|
|
|
|
pdf: Same as ``Filters.document.mime_type("application/pdf")``-
|
|
|
|
py: Same as ``Filters.document.mime_type("text/x-python")``-
|
|
|
|
svg: Same as ``Filters.document.mime_type("image/svg+xml")``-
|
|
|
|
txt: Same as ``Filters.document.mime_type("text/plain")``-
|
|
|
|
targz: Same as ``Filters.document.mime_type("application/x-compressed-tar")``-
|
|
|
|
wav: Same as ``Filters.document.mime_type("audio/x-wav")``-
|
|
|
|
xml: Same as ``Filters.document.mime_type("application/xml")``-
|
|
|
|
zip: Same as ``Filters.document.mime_type("application/zip")``-
|
|
|
|
"""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
class _Animation(BaseFilter):
|
|
|
|
name = 'Filters.animation'
|
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.animation)
|
|
|
|
|
|
|
|
animation = _Animation()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.Animation`."""
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Photo(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.photo'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.photo)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
photo = _Photo()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.PhotoSize`."""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Sticker(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.sticker'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.sticker)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
sticker = _Sticker()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.Sticker`."""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Video(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.video'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.video)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
video = _Video()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.Video`."""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Voice(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.voice'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.voice)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
voice = _Voice()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.Voice`."""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2018-04-14 21:53:54 +02:00
|
|
|
class _VideoNote(BaseFilter):
|
|
|
|
name = 'Filters.video_note'
|
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.video_note)
|
|
|
|
|
|
|
|
video_note = _VideoNote()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.VideoNote`."""
|
2018-04-14 21:53:54 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Contact(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.contact'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.contact)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
contact = _Contact()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.Contact`."""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Location(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.location'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.location)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
location = _Location()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.Location`."""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Venue(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.venue'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.venue)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
venue = _Venue()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.Venue`."""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _StatusUpdate(BaseFilter):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Subset for messages containing a status update.
|
2017-07-23 22:33:08 +02:00
|
|
|
|
|
|
|
Examples:
|
2017-10-18 21:00:17 +02:00
|
|
|
Use these filters like: ``Filters.status_update.new_chat_members`` etc. Or use just
|
2017-07-23 22:33:08 +02:00
|
|
|
``Filters.status_update`` for all status update messages.
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2017-07-23 22:33:08 +02:00
|
|
|
"""
|
2019-02-13 12:07:25 +01:00
|
|
|
update_filter = True
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2017-06-01 04:09:30 +02:00
|
|
|
class _NewChatMembers(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.status_update.new_chat_members'
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.new_chat_members)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
new_chat_members = _NewChatMembers()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :attr:`telegram.Message.new_chat_members`."""
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
class _LeftChatMember(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.status_update.left_chat_member'
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.left_chat_member)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
left_chat_member = _LeftChatMember()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :attr:`telegram.Message.left_chat_member`."""
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
class _NewChatTitle(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.status_update.new_chat_title'
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.new_chat_title)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
new_chat_title = _NewChatTitle()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :attr:`telegram.Message.new_chat_title`."""
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
class _NewChatPhoto(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.status_update.new_chat_photo'
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.new_chat_photo)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
new_chat_photo = _NewChatPhoto()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :attr:`telegram.Message.new_chat_photo`."""
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
class _DeleteChatPhoto(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.status_update.delete_chat_photo'
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.delete_chat_photo)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
delete_chat_photo = _DeleteChatPhoto()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :attr:`telegram.Message.delete_chat_photo`."""
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
class _ChatCreated(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.status_update.chat_created'
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
2018-11-01 10:18:07 +01:00
|
|
|
return bool(message.group_chat_created or message.supergroup_chat_created
|
|
|
|
or message.channel_chat_created)
|
2017-06-01 04:09:30 +02:00
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
chat_created = _ChatCreated()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :attr:`telegram.Message.group_chat_created`,
|
2017-07-23 22:33:08 +02:00
|
|
|
:attr: `telegram.Message.supergroup_chat_created` or
|
|
|
|
:attr: `telegram.Message.channel_chat_created`."""
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
class _Migrate(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.status_update.migrate'
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.migrate_from_chat_id or message.migrate_to_chat_id)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
migrate = _Migrate()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :attr:`telegram.Message.migrate_from_chat_id` or
|
2017-09-15 23:56:16 +02:00
|
|
|
:attr: `telegram.Message.migrate_to_chat_id`."""
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
class _PinnedMessage(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.status_update.pinned_message'
|
2017-06-01 04:09:30 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.pinned_message)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
pinned_message = _PinnedMessage()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :attr:`telegram.Message.pinned_message`."""
|
2017-06-21 13:46:03 +02:00
|
|
|
|
2018-02-18 16:11:04 +01:00
|
|
|
class _ConnectedWebsite(BaseFilter):
|
|
|
|
name = 'Filters.status_update.connected_website'
|
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.connected_website)
|
|
|
|
|
|
|
|
connected_website = _ConnectedWebsite()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :attr:`telegram.Message.connected_website`."""
|
2018-02-18 16:11:04 +01:00
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.status_update'
|
2017-06-01 04:09:30 +02:00
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2018-11-01 10:18:07 +01:00
|
|
|
return bool(self.new_chat_members(message) or self.left_chat_member(message)
|
|
|
|
or self.new_chat_title(message) or self.new_chat_photo(message)
|
|
|
|
or self.delete_chat_photo(message) or self.chat_created(message)
|
|
|
|
or self.migrate(message) or self.pinned_message(message)
|
|
|
|
or self.connected_website(message))
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
status_update = _StatusUpdate()
|
2017-09-01 08:41:15 +02:00
|
|
|
"""Subset for messages containing a status update.
|
|
|
|
|
|
|
|
Examples:
|
2018-02-22 13:17:06 +01:00
|
|
|
Use these filters like: ``Filters.status_update.new_chat_members`` etc. Or use just
|
2017-09-01 08:41:15 +02:00
|
|
|
``Filters.status_update`` for all status update messages.
|
|
|
|
|
|
|
|
Attributes:
|
2019-02-18 20:04:52 +01:00
|
|
|
chat_created: Messages that contain
|
2017-09-01 08:41:15 +02:00
|
|
|
:attr:`telegram.Message.group_chat_created`,
|
|
|
|
:attr:`telegram.Message.supergroup_chat_created` or
|
|
|
|
:attr:`telegram.Message.channel_chat_created`.
|
2019-02-18 20:04:52 +01:00
|
|
|
delete_chat_photo: Messages that contain
|
2017-09-01 08:41:15 +02:00
|
|
|
:attr:`telegram.Message.delete_chat_photo`.
|
2019-02-18 20:04:52 +01:00
|
|
|
left_chat_member: Messages that contain
|
2017-09-01 08:41:15 +02:00
|
|
|
:attr:`telegram.Message.left_chat_member`.
|
2019-02-18 20:04:52 +01:00
|
|
|
migrate: Messages that contain
|
2017-09-01 08:41:15 +02:00
|
|
|
:attr:`telegram.Message.migrate_from_chat_id` or
|
|
|
|
:attr: `telegram.Message.migrate_from_chat_id`.
|
2019-02-18 20:04:52 +01:00
|
|
|
new_chat_members: Messages that contain
|
2018-02-22 13:17:06 +01:00
|
|
|
:attr:`telegram.Message.new_chat_members`.
|
2019-02-18 20:04:52 +01:00
|
|
|
new_chat_photo: Messages that contain
|
2017-09-01 08:41:15 +02:00
|
|
|
:attr:`telegram.Message.new_chat_photo`.
|
2019-02-18 20:04:52 +01:00
|
|
|
new_chat_title: Messages that contain
|
2017-09-01 08:41:15 +02:00
|
|
|
:attr:`telegram.Message.new_chat_title`.
|
2019-02-18 20:04:52 +01:00
|
|
|
pinned_message: Messages that contain
|
2017-09-01 08:41:15 +02:00
|
|
|
:attr:`telegram.Message.pinned_message`.
|
|
|
|
"""
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class _Forwarded(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.forwarded'
|
2016-09-14 19:29:15 +02:00
|
|
|
|
2016-09-24 18:20:32 +02:00
|
|
|
def filter(self, message):
|
2016-09-14 19:29:15 +02:00
|
|
|
return bool(message.forward_date)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
forwarded = _Forwarded()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that are forwarded."""
|
2016-09-24 18:30:58 +02:00
|
|
|
|
2016-10-19 12:35:50 +02:00
|
|
|
class _Game(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.game'
|
2016-10-19 12:35:50 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.game)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
game = _Game()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.Game`."""
|
2016-10-19 12:35:50 +02:00
|
|
|
|
2016-09-25 00:30:04 +02:00
|
|
|
class entity(BaseFilter):
|
2017-07-23 22:33:08 +02:00
|
|
|
"""
|
|
|
|
Filters messages to only allow those which have a :class:`telegram.MessageEntity`
|
2016-09-24 18:30:58 +02:00
|
|
|
where their `type` matches `entity_type`.
|
|
|
|
|
2017-07-23 22:33:08 +02:00
|
|
|
Examples:
|
|
|
|
Example ``MessageHandler(Filters.entity("hashtag"), callback_method)``
|
|
|
|
|
2016-09-24 18:30:58 +02:00
|
|
|
Args:
|
|
|
|
entity_type: Entity type to check for. All types can be found as constants
|
|
|
|
in :class:`telegram.MessageEntity`.
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2016-09-24 18:30:58 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, entity_type):
|
|
|
|
self.entity_type = entity_type
|
2017-06-21 13:46:03 +02:00
|
|
|
self.name = 'Filters.entity({})'.format(self.entity_type)
|
2016-09-24 18:30:58 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
2019-02-13 12:07:25 +01:00
|
|
|
"""""" # remove method from docs
|
2018-04-20 13:24:40 +02:00
|
|
|
return any(entity.type == self.entity_type for entity in message.entities)
|
|
|
|
|
|
|
|
class caption_entity(BaseFilter):
|
|
|
|
"""
|
|
|
|
Filters media messages to only allow those which have a :class:`telegram.MessageEntity`
|
|
|
|
where their `type` matches `entity_type`.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Example ``MessageHandler(Filters.caption_entity("hashtag"), callback_method)``
|
|
|
|
|
|
|
|
Args:
|
|
|
|
entity_type: Caption Entity type to check for. All types can be found as constants
|
|
|
|
in :class:`telegram.MessageEntity`.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, entity_type):
|
|
|
|
self.entity_type = entity_type
|
|
|
|
self.name = 'Filters.caption_entity({})'.format(self.entity_type)
|
|
|
|
|
|
|
|
def filter(self, message):
|
2019-02-13 12:07:25 +01:00
|
|
|
"""""" # remove method from docs
|
2018-04-20 13:24:40 +02:00
|
|
|
return any(entity.type == self.entity_type for entity in message.caption_entities)
|
2017-04-23 23:22:05 +02:00
|
|
|
|
|
|
|
class _Private(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.private'
|
2017-04-23 23:22:05 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return message.chat.type == Chat.PRIVATE
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
private = _Private()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages sent in a private chat."""
|
2017-04-23 23:22:05 +02:00
|
|
|
|
|
|
|
class _Group(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.group'
|
2017-04-23 23:22:05 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return message.chat.type in [Chat.GROUP, Chat.SUPERGROUP]
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
group = _Group()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages sent in a group chat."""
|
2017-05-22 12:13:00 +02:00
|
|
|
|
2017-06-19 19:50:44 +02:00
|
|
|
class user(BaseFilter):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Filters messages to allow only those which are from specified user ID.
|
2017-06-22 10:35:59 +02:00
|
|
|
|
2017-07-23 22:33:08 +02:00
|
|
|
Examples:
|
|
|
|
``MessageHandler(Filters.user(1234), callback_method)``
|
2017-06-19 19:50:44 +02:00
|
|
|
|
|
|
|
Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
user_id(:obj:`int` | List[:obj:`int`], optional): Which user ID(s) to allow through.
|
|
|
|
username(:obj:`str` | List[:obj:`str`], optional): Which username(s) to allow through.
|
|
|
|
If username starts with '@' symbol, it will be ignored.
|
2017-06-20 09:43:07 +02:00
|
|
|
|
|
|
|
Raises:
|
2017-07-23 22:33:08 +02:00
|
|
|
ValueError: If chat_id and username are both present, or neither is.
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2017-06-19 19:50:44 +02:00
|
|
|
"""
|
|
|
|
|
2017-06-20 09:43:07 +02:00
|
|
|
def __init__(self, user_id=None, username=None):
|
2017-06-22 10:35:59 +02:00
|
|
|
if not (bool(user_id) ^ bool(username)):
|
|
|
|
raise ValueError('One and only one of user_id or username must be used')
|
2017-06-22 12:19:49 +02:00
|
|
|
if user_id is not None and isinstance(user_id, int):
|
|
|
|
self.user_ids = [user_id]
|
2017-06-20 09:43:07 +02:00
|
|
|
else:
|
2017-06-22 12:19:49 +02:00
|
|
|
self.user_ids = user_id
|
|
|
|
if username is None:
|
|
|
|
self.usernames = username
|
2017-07-01 17:08:45 +02:00
|
|
|
elif isinstance(username, string_types):
|
2017-06-22 12:19:49 +02:00
|
|
|
self.usernames = [username.replace('@', '')]
|
|
|
|
else:
|
|
|
|
self.usernames = [user.replace('@', '') for user in username]
|
2017-06-19 19:50:44 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
2019-02-13 12:07:25 +01:00
|
|
|
"""""" # remove method from docs
|
2017-06-22 12:19:49 +02:00
|
|
|
if self.user_ids is not None:
|
|
|
|
return bool(message.from_user and message.from_user.id in self.user_ids)
|
2017-06-20 09:43:07 +02:00
|
|
|
else:
|
2017-06-22 12:19:49 +02:00
|
|
|
# self.usernames is not None
|
2018-11-01 10:18:07 +01:00
|
|
|
return bool(message.from_user and message.from_user.username
|
|
|
|
and message.from_user.username in self.usernames)
|
2017-06-19 19:50:44 +02:00
|
|
|
|
|
|
|
class chat(BaseFilter):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Filters messages to allow only those which are from specified chat ID.
|
2017-06-22 10:35:59 +02:00
|
|
|
|
2017-07-23 22:33:08 +02:00
|
|
|
Examples:
|
|
|
|
``MessageHandler(Filters.chat(-1234), callback_method)``
|
2017-06-19 19:50:44 +02:00
|
|
|
|
|
|
|
Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
chat_id(:obj:`int` | List[:obj:`int`], optional): Which chat ID(s) to allow through.
|
|
|
|
username(:obj:`str` | List[:obj:`str`], optional): Which username(s) to allow through.
|
|
|
|
If username start swith '@' symbol, it will be ignored.
|
2017-06-20 09:43:07 +02:00
|
|
|
|
|
|
|
Raises:
|
2017-07-23 22:33:08 +02:00
|
|
|
ValueError: If chat_id and username are both present, or neither is.
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2017-06-19 19:50:44 +02:00
|
|
|
"""
|
|
|
|
|
2017-06-20 09:43:07 +02:00
|
|
|
def __init__(self, chat_id=None, username=None):
|
2017-06-22 10:35:59 +02:00
|
|
|
if not (bool(chat_id) ^ bool(username)):
|
2017-06-22 12:19:49 +02:00
|
|
|
raise ValueError('One and only one of chat_id or username must be used')
|
|
|
|
if chat_id is not None and isinstance(chat_id, int):
|
|
|
|
self.chat_ids = [chat_id]
|
|
|
|
else:
|
|
|
|
self.chat_ids = chat_id
|
|
|
|
if username is None:
|
|
|
|
self.usernames = username
|
2017-07-01 17:08:45 +02:00
|
|
|
elif isinstance(username, string_types):
|
2017-06-22 12:19:49 +02:00
|
|
|
self.usernames = [username.replace('@', '')]
|
2017-06-20 09:43:07 +02:00
|
|
|
else:
|
2017-06-22 12:19:49 +02:00
|
|
|
self.usernames = [chat.replace('@', '') for chat in username]
|
2017-06-19 19:50:44 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
2019-02-13 12:07:25 +01:00
|
|
|
"""""" # remove method from docs
|
2017-06-22 12:19:49 +02:00
|
|
|
if self.chat_ids is not None:
|
|
|
|
return bool(message.chat_id in self.chat_ids)
|
2017-06-20 09:43:07 +02:00
|
|
|
else:
|
2017-06-22 12:19:49 +02:00
|
|
|
# self.usernames is not None
|
|
|
|
return bool(message.chat.username and message.chat.username in self.usernames)
|
2017-06-19 19:50:44 +02:00
|
|
|
|
2017-05-22 12:13:00 +02:00
|
|
|
class _Invoice(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.invoice'
|
2017-05-22 12:13:00 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.invoice)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
invoice = _Invoice()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain :class:`telegram.Invoice`."""
|
2017-05-22 12:13:00 +02:00
|
|
|
|
|
|
|
class _SuccessfulPayment(BaseFilter):
|
2017-06-21 13:46:03 +02:00
|
|
|
name = 'Filters.successful_payment'
|
2017-05-22 12:13:00 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.successful_payment)
|
|
|
|
|
2017-06-21 13:46:03 +02:00
|
|
|
successful_payment = _SuccessfulPayment()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that confirm a :class:`telegram.SuccessfulPayment`."""
|
2017-06-01 21:01:04 +02:00
|
|
|
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
class _PassportData(BaseFilter):
|
|
|
|
name = 'Filters.passport_data'
|
|
|
|
|
|
|
|
def filter(self, message):
|
|
|
|
return bool(message.passport_data)
|
|
|
|
|
|
|
|
passport_data = _PassportData()
|
2019-02-18 20:04:52 +01:00
|
|
|
"""Messages that contain a :class:`telegram.PassportData`"""
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
|
2017-05-21 14:00:53 +02:00
|
|
|
class language(BaseFilter):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""Filters messages to only allow those which are from users with a certain language code.
|
|
|
|
|
2019-02-18 20:04:52 +01:00
|
|
|
Note:
|
|
|
|
According to official telegram api documentation, not every single user has the
|
|
|
|
`language_code` attribute. Do not count on this filter working on all users.
|
2017-05-21 14:00:53 +02:00
|
|
|
|
2017-07-23 22:33:08 +02:00
|
|
|
Examples:
|
|
|
|
``MessageHandler(Filters.language("en"), callback_method)``
|
|
|
|
|
2017-05-21 14:00:53 +02:00
|
|
|
Args:
|
2017-07-23 22:33:08 +02:00
|
|
|
lang (:obj:`str` | List[:obj:`str`]): Which language code(s) to allow through. This
|
|
|
|
will be matched using ``.startswith`` meaning that 'en' will match both 'en_US'
|
|
|
|
and 'en_GB'.
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2017-05-21 14:00:53 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, lang):
|
2017-07-01 17:08:45 +02:00
|
|
|
if isinstance(lang, string_types):
|
2017-05-21 14:00:53 +02:00
|
|
|
self.lang = [lang]
|
|
|
|
else:
|
|
|
|
self.lang = lang
|
2017-06-21 13:46:03 +02:00
|
|
|
self.name = 'Filters.language({})'.format(self.lang)
|
2017-05-21 14:00:53 +02:00
|
|
|
|
|
|
|
def filter(self, message):
|
2019-02-13 12:07:25 +01:00
|
|
|
"""""" # remove method from docs
|
2017-05-21 14:00:53 +02:00
|
|
|
return message.from_user.language_code and any(
|
|
|
|
[message.from_user.language_code.startswith(x) for x in self.lang])
|
2019-02-13 12:07:25 +01:00
|
|
|
|
|
|
|
class _UpdateType(BaseFilter):
|
|
|
|
update_filter = True
|
|
|
|
|
|
|
|
class _Message(BaseFilter):
|
|
|
|
update_filter = True
|
|
|
|
|
|
|
|
def filter(self, update):
|
|
|
|
return update.message is not None
|
|
|
|
|
|
|
|
message = _Message()
|
|
|
|
|
|
|
|
class _EditedMessage(BaseFilter):
|
|
|
|
update_filter = True
|
|
|
|
|
|
|
|
def filter(self, update):
|
|
|
|
return update.edited_message is not None
|
|
|
|
|
|
|
|
edited_message = _EditedMessage()
|
|
|
|
|
|
|
|
class _Messages(BaseFilter):
|
|
|
|
update_filter = True
|
|
|
|
|
|
|
|
def filter(self, update):
|
|
|
|
return update.message is not None or update.edited_message is not None
|
|
|
|
|
|
|
|
messages = _Messages()
|
|
|
|
|
|
|
|
class _ChannelPost(BaseFilter):
|
|
|
|
update_filter = True
|
|
|
|
|
|
|
|
def filter(self, update):
|
|
|
|
return update.channel_post is not None
|
|
|
|
|
|
|
|
channel_post = _ChannelPost()
|
|
|
|
|
|
|
|
class _EditedChannelPost(BaseFilter):
|
|
|
|
update_filter = True
|
|
|
|
|
|
|
|
def filter(self, update):
|
|
|
|
return update.edited_channel_post is not None
|
|
|
|
|
|
|
|
edited_channel_post = _EditedChannelPost()
|
|
|
|
|
|
|
|
class _ChannelPosts(BaseFilter):
|
|
|
|
update_filter = True
|
|
|
|
|
|
|
|
def filter(self, update):
|
|
|
|
return update.channel_post is not None or update.edited_channel_post is not None
|
|
|
|
|
|
|
|
channel_posts = _ChannelPosts()
|
|
|
|
|
|
|
|
def filter(self, update):
|
|
|
|
return self.messages(update) or self.channel_posts(update)
|
|
|
|
|
|
|
|
update = _UpdateType()
|
|
|
|
"""Subset for filtering the type of update.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Use these filters like: ``Filters.update.message`` or
|
|
|
|
``Filters.update.channel_posts`` etc. Or use just ``Filters.update`` for all
|
|
|
|
types.
|
|
|
|
|
|
|
|
Attributes:
|
2019-02-18 20:04:52 +01:00
|
|
|
message: Updates with :attr:`telegram.Update.message`
|
|
|
|
edited_message: Updates with :attr:`telegram.Update.edited_message`
|
|
|
|
messages: Updates with either :attr:`telegram.Update.message` or
|
2019-02-13 12:07:25 +01:00
|
|
|
:attr:`telegram.Update.edited_message`
|
2019-02-18 20:04:52 +01:00
|
|
|
channel_post: Updates with :attr:`telegram.Update.channel_post`
|
|
|
|
edited_channel_post: Updates with
|
2019-02-13 12:07:25 +01:00
|
|
|
:attr:`telegram.Update.edited_channel_post`
|
2019-02-18 20:04:52 +01:00
|
|
|
channel_posts: Updates with either :attr:`telegram.Update.channel_post` or
|
2019-02-13 12:07:25 +01:00
|
|
|
:attr:`telegram.Update.edited_channel_post`
|
|
|
|
"""
|