mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-05 14:10:56 +03:00
Support filtering events.Raw by update type
This commit is contained in:
parent
5c6ac18a52
commit
ce7e5abb58
|
@ -1,4 +1,4 @@
|
||||||
from .common import Raw
|
from .raw import Raw
|
||||||
from .chataction import ChatAction
|
from .chataction import ChatAction
|
||||||
from .messagedeleted import MessageDeleted
|
from .messagedeleted import MessageDeleted
|
||||||
from .messageedited import MessageEdited
|
from .messageedited import MessageEdited
|
||||||
|
|
|
@ -209,17 +209,6 @@ class EventCommon(abc.ABC):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class Raw(EventBuilder):
|
|
||||||
"""
|
|
||||||
Represents a raw event. The event is the update itself.
|
|
||||||
"""
|
|
||||||
def resolve(self, client):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def build(self, update):
|
|
||||||
return update
|
|
||||||
|
|
||||||
|
|
||||||
def name_inner_event(cls):
|
def name_inner_event(cls):
|
||||||
"""Decorator to rename cls.Event 'Event' as 'cls.Event'"""
|
"""Decorator to rename cls.Event 'Event' as 'cls.Event'"""
|
||||||
if hasattr(cls, 'Event'):
|
if hasattr(cls, 'Event'):
|
||||||
|
|
30
telethon/events/raw.py
Normal file
30
telethon/events/raw.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
from .common import EventBuilder
|
||||||
|
from .. import utils
|
||||||
|
|
||||||
|
|
||||||
|
class Raw(EventBuilder):
|
||||||
|
"""
|
||||||
|
Represents a raw event. The event is the update itself.
|
||||||
|
|
||||||
|
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``.
|
||||||
|
"""
|
||||||
|
def __init__(self, types=None):
|
||||||
|
super().__init__()
|
||||||
|
if not types:
|
||||||
|
self.types = None
|
||||||
|
elif not utils.is_list_like(types):
|
||||||
|
assert isinstance(types, type)
|
||||||
|
self.types = types
|
||||||
|
else:
|
||||||
|
assert all(isinstance(x, type) for x in types)
|
||||||
|
self.types = tuple(types)
|
||||||
|
|
||||||
|
def resolve(self, client):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def build(self, update):
|
||||||
|
if not self.types or isinstance(update, self.types):
|
||||||
|
return update
|
Loading…
Reference in New Issue
Block a user