mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-06 05:00:23 +03:00
Merged master and performed changes as requested
This commit is contained in:
parent
ebcfd1ed99
commit
1bb61cc84e
|
@ -131,18 +131,21 @@ propagation of the update through your handlers to stop:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
from telethon.events import StopPropagation
|
||||||
|
|
||||||
@client.on(events.NewMessage)
|
@client.on(events.NewMessage)
|
||||||
def _(event):
|
def _(event):
|
||||||
# ... some conditions
|
# ... some conditions
|
||||||
event.delete()
|
event.delete()
|
||||||
|
|
||||||
# Other handlers won't have an event to work with
|
# Other handlers won't have an event to work with
|
||||||
raise client.StopPropagation
|
raise StopPropagation
|
||||||
|
|
||||||
@client.on(events.NewMessage)
|
@client.on(events.NewMessage)
|
||||||
def _(event):
|
def _(event):
|
||||||
pass # Will never be reached, because
|
# Will never be reached, because it is the second handler
|
||||||
# it is the second handler in the chain.
|
# in the chain.
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
Events module
|
Events module
|
||||||
|
|
|
@ -873,3 +873,26 @@ class MessageChanged(_EventBuilder):
|
||||||
self.edited = bool(edit_msg)
|
self.edited = bool(edit_msg)
|
||||||
self.deleted = bool(deleted_ids)
|
self.deleted = bool(deleted_ids)
|
||||||
self.deleted_ids = deleted_ids or []
|
self.deleted_ids = deleted_ids or []
|
||||||
|
|
||||||
|
|
||||||
|
class StopPropagation(Exception):
|
||||||
|
"""
|
||||||
|
If this Exception is found to be raised in any of the handlers for a
|
||||||
|
given update, it will stop the execution of all other registered
|
||||||
|
event handlers in the chain.
|
||||||
|
Think of it like a ``StopIteration`` exception in a for loop.
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
```
|
||||||
|
@client.on(events.NewMessage)
|
||||||
|
def delete(event):
|
||||||
|
event.delete()
|
||||||
|
# Other handlers won't have an event to work with
|
||||||
|
raise StopPropagation
|
||||||
|
|
||||||
|
@client.on(events.NewMessage)
|
||||||
|
def _(event):
|
||||||
|
# Will never be reached, because it is the second handler in the chain.
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
|
|
@ -1887,9 +1887,10 @@ class TelegramClient(TelegramBareClient):
|
||||||
event._client = self
|
event._client = self
|
||||||
try:
|
try:
|
||||||
callback(event)
|
callback(event)
|
||||||
except StopPropagation:
|
except events.StopPropagation:
|
||||||
__log__.info("Event handler '{}' stopped chain of propagation for update {}.".format(
|
__log__.debug("Event handler '{}' stopped chain of "
|
||||||
callback.__name__, type(update).__name__))
|
"propagation for update {}.".format(
|
||||||
|
callback.__name__, type(update).__name__))
|
||||||
break
|
break
|
||||||
|
|
||||||
def add_event_handler(self, callback, event=None):
|
def add_event_handler(self, callback, event=None):
|
||||||
|
@ -2130,30 +2131,3 @@ class TelegramClient(TelegramBareClient):
|
||||||
)
|
)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
|
||||||
# region Exceptions
|
|
||||||
|
|
||||||
class StopPropagation(Exception):
|
|
||||||
"""
|
|
||||||
If this Exception is found to be raised in any of the handlers for a
|
|
||||||
given update, it will stop the execution of all other registered
|
|
||||||
event handlers in the chain.
|
|
||||||
Think of it like a ``StopIteration`` exception in a for loop.
|
|
||||||
|
|
||||||
Example usage:
|
|
||||||
```
|
|
||||||
@client.on(events.NewMessage)
|
|
||||||
def delete(event):
|
|
||||||
event.delete()
|
|
||||||
# Other handlers won't have an event to work with
|
|
||||||
raise StopPropagation
|
|
||||||
|
|
||||||
@client.on(events.NewMessage)
|
|
||||||
def _(event):
|
|
||||||
pass # Will never be reached, because
|
|
||||||
# it is the second handler in the chain.
|
|
||||||
```
|
|
||||||
"""
|
|
||||||
|
|
||||||
# endregion
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user