mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-23 15:54:12 +03:00
Allow specifying no event type to default to events.Raw
This commit is contained in:
parent
e5aecca79c
commit
9ef75e5070
|
@ -1888,7 +1888,7 @@ class TelegramClient(TelegramBareClient):
|
|||
event._client = self
|
||||
callback(event)
|
||||
|
||||
def add_event_handler(self, callback, event):
|
||||
def add_event_handler(self, callback, event=None):
|
||||
"""
|
||||
Registers the given callback to be called on the specified event.
|
||||
|
||||
|
@ -1896,9 +1896,12 @@ class TelegramClient(TelegramBareClient):
|
|||
callback (:obj:`callable`):
|
||||
The callable function accepting one parameter to be used.
|
||||
|
||||
event (:obj:`_EventBuilder` | :obj:`type`):
|
||||
event (:obj:`_EventBuilder` | :obj:`type`, optional):
|
||||
The event builder class or instance to be used,
|
||||
for instance ``events.NewMessage``.
|
||||
|
||||
If left unspecified, ``events.Raw`` (the ``Update`` objects
|
||||
with no further processing) will be passed instead.
|
||||
"""
|
||||
if self.updates.workers is None:
|
||||
warnings.warn(
|
||||
|
@ -1910,6 +1913,8 @@ class TelegramClient(TelegramBareClient):
|
|||
self.updates.handler = self._on_handler
|
||||
if isinstance(event, type):
|
||||
event = event()
|
||||
elif not event:
|
||||
event = events.Raw()
|
||||
|
||||
event.resolve(self)
|
||||
self._event_builders.append((event, callback))
|
||||
|
|
Loading…
Reference in New Issue
Block a user