mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-06 05:00:23 +03:00
Allow access to result of EventBuilder's func
predicate in event handler callbacks
This commit is contained in:
parent
7dece209a0
commit
9672b3ecfb
|
@ -63,7 +63,8 @@ class EventBuilder(abc.ABC):
|
||||||
|
|
||||||
@client.on(events.NewMessage(func=lambda e: e.is_private))
|
@client.on(events.NewMessage(func=lambda e: e.is_private))
|
||||||
async def handler(event):
|
async def handler(event):
|
||||||
pass # code here
|
# Access the result of func
|
||||||
|
assert event.func_result is True
|
||||||
"""
|
"""
|
||||||
self_id = None
|
self_id = None
|
||||||
|
|
||||||
|
@ -114,7 +115,13 @@ class EventBuilder(abc.ABC):
|
||||||
# If it doesn't match but it's a whitelist ignore.
|
# If it doesn't match but it's a whitelist ignore.
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not self.func or self.func(event):
|
if self.func:
|
||||||
|
func_result = self.func(event)
|
||||||
|
|
||||||
|
if not func_result:
|
||||||
|
return None
|
||||||
|
|
||||||
|
event.func_result = func_result
|
||||||
return event
|
return event
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,8 +133,11 @@ class EventCommon(ChatGetter, abc.ABC):
|
||||||
<telethon.tl.custom.chatgetter.ChatGetter>` which
|
<telethon.tl.custom.chatgetter.ChatGetter>` which
|
||||||
means you have access to all chat properties and methods.
|
means you have access to all chat properties and methods.
|
||||||
|
|
||||||
In addition, you can access the `original_update`
|
You can access the `original_update` field which
|
||||||
field which contains the original :tl:`Update`.
|
contains the original :tl:`Update`.
|
||||||
|
|
||||||
|
In addition, the result of the event builder's `func`
|
||||||
|
predicate can be accessed via `event.func_result`.
|
||||||
"""
|
"""
|
||||||
_event_name = 'Event'
|
_event_name = 'Event'
|
||||||
|
|
||||||
|
@ -140,6 +150,7 @@ class EventCommon(ChatGetter, abc.ABC):
|
||||||
self._chat = None
|
self._chat = None
|
||||||
self._broadcast = broadcast
|
self._broadcast = broadcast
|
||||||
self.original_update = None
|
self.original_update = None
|
||||||
|
self.func_result = None
|
||||||
|
|
||||||
def _set_client(self, client):
|
def _set_client(self, client):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user