2018-04-28 14:37:19 +03:00
|
|
|
from .common import EventBuilder
|
|
|
|
from .. import utils
|
|
|
|
|
|
|
|
|
|
|
|
class Raw(EventBuilder):
|
|
|
|
"""
|
2019-06-11 12:09:22 +03:00
|
|
|
Raw events are not actual events. Instead, they are the raw
|
|
|
|
:tl:`Update` object that Telegram sends. You normally shouldn't
|
|
|
|
need these.
|
2018-04-28 14:37:19 +03:00
|
|
|
|
|
|
|
Args:
|
|
|
|
types (`list` | `tuple` | `type`, optional):
|
|
|
|
The type or types that the :tl:`Update` instance must be.
|
|
|
|
Equivalent to ``if not isinstance(update, types): return``.
|
|
|
|
"""
|
2018-09-09 16:48:54 +03:00
|
|
|
def __init__(self, types=None, *, func=None):
|
|
|
|
super().__init__(func=func)
|
2018-04-28 14:37:19 +03:00
|
|
|
if not types:
|
|
|
|
self.types = None
|
|
|
|
elif not utils.is_list_like(types):
|
2018-08-14 20:14:13 +03:00
|
|
|
if not isinstance(types, type):
|
|
|
|
raise TypeError('Invalid input type given %s', types)
|
|
|
|
|
2018-04-28 14:37:19 +03:00
|
|
|
self.types = types
|
|
|
|
else:
|
2018-08-14 20:14:13 +03:00
|
|
|
if not all(isinstance(x, type) for x in types):
|
|
|
|
raise TypeError('Invalid input types given %s', types)
|
|
|
|
|
2018-04-28 14:37:19 +03:00
|
|
|
self.types = tuple(types)
|
|
|
|
|
2018-06-13 17:20:15 +03:00
|
|
|
async def resolve(self, client):
|
2018-08-21 12:08:08 +03:00
|
|
|
self.resolved = True
|
2018-04-28 14:37:19 +03:00
|
|
|
|
2018-07-19 02:47:32 +03:00
|
|
|
@classmethod
|
2019-08-07 01:46:19 +03:00
|
|
|
def build(cls, update, others=None, self_id=None):
|
2018-07-11 12:22:43 +03:00
|
|
|
return update
|
|
|
|
|
|
|
|
def filter(self, event):
|
2018-09-09 16:48:54 +03:00
|
|
|
if ((not self.types or isinstance(event, self.types))
|
|
|
|
and (not self.func or self.func(event))):
|
2018-07-11 12:22:43 +03:00
|
|
|
return event
|