mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-02 11:10:18 +03:00
More fixes for suggestions:
- I forgot some places with func call - More suitable docs for filter - `if` in full block
This commit is contained in:
parent
a6e8f93d30
commit
85cfe016b0
|
@ -118,8 +118,10 @@ class CallbackQuery(EventBuilder):
|
|||
elif event.query.data != self.match:
|
||||
return
|
||||
|
||||
if not self.func or self.func(event):
|
||||
return event
|
||||
if self.func:
|
||||
# Return the result of func directly as it may need to be awaited
|
||||
return self.func(event)
|
||||
return True
|
||||
|
||||
class Event(EventCommon, SenderGetter):
|
||||
"""
|
||||
|
|
|
@ -105,9 +105,8 @@ class EventBuilder(abc.ABC):
|
|||
|
||||
def filter(self, event):
|
||||
"""
|
||||
If the ID of ``event._chat_peer`` isn't in the chats set (or it is
|
||||
but the set is a blacklist) returns `True`, otherwise `False`.
|
||||
May also return awaitable which awaits to bool-able value.
|
||||
Returns a truthy value if the event passed the filter and should be
|
||||
used, or falsy otherwise. The return value may need to be awaited.
|
||||
|
||||
The events must have been resolved before this can be called.
|
||||
"""
|
||||
|
|
|
@ -46,6 +46,8 @@ class Raw(EventBuilder):
|
|||
return update
|
||||
|
||||
def filter(self, event):
|
||||
if ((not self.types or isinstance(event, self.types))
|
||||
and (not self.func or self.func(event))):
|
||||
if not self.types or isinstance(event, self.types):
|
||||
if self.func:
|
||||
# Return the result of func directly as it may need to be awaited
|
||||
return self.func(event)
|
||||
return event
|
||||
|
|
|
@ -316,7 +316,9 @@ class Conversation(ChatGetter):
|
|||
|
||||
if inst:
|
||||
filter = ev.filter(inst)
|
||||
filter = (await filter) if inspect.isawaitable(filter) else filter
|
||||
if inspect.isawaitable(filter):
|
||||
filter = await filter
|
||||
|
||||
if filter:
|
||||
fut.set_result(inst)
|
||||
del self._custom[key]
|
||||
|
|
Loading…
Reference in New Issue
Block a user