Support custom-callback filter for all events

This commit is contained in:
Lonami Exo
2018-09-09 15:48:54 +02:00
parent 11ef4ce370
commit 2f09e5c335
7 changed files with 36 additions and 17 deletions

View File

@@ -11,8 +11,8 @@ class Raw(EventBuilder):
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__()
def __init__(self, types=None, *, func=None):
super().__init__(func=func)
if not types:
self.types = None
elif not utils.is_list_like(types):
@@ -34,5 +34,6 @@ class Raw(EventBuilder):
return update
def filter(self, event):
if not self.types or isinstance(event, self.types):
if ((not self.types or isinstance(event, self.types))
and (not self.func or self.func(event))):
return event