mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 01:16:35 +03:00
Handle callable from_users
for NewMessage
events
This commit is contained in:
parent
aec957d62d
commit
3a5e035ea8
|
@ -19,7 +19,7 @@ class NewMessage(EventBuilder):
|
|||
If set to `True`, only **outgoing** messages will be handled.
|
||||
Mutually exclusive with ``incoming`` (can only set one of either).
|
||||
|
||||
from_users (`entity`, optional):
|
||||
from_users (`entity`, `callable`, optional):
|
||||
Unlike `chats`, this parameter filters the *senders* of the
|
||||
message. That is, only messages *sent by these users* will be
|
||||
handled. Use `chats` if you want private messages with this/these
|
||||
|
@ -74,6 +74,7 @@ class NewMessage(EventBuilder):
|
|||
self.outgoing = outgoing
|
||||
self.from_users = from_users
|
||||
self.forwards = forwards
|
||||
|
||||
if isinstance(pattern, str):
|
||||
self.pattern = re.compile(pattern).match
|
||||
elif not pattern or callable(pattern):
|
||||
|
@ -83,6 +84,9 @@ class NewMessage(EventBuilder):
|
|||
else:
|
||||
raise TypeError('Invalid pattern type given')
|
||||
|
||||
if callable(from_users):
|
||||
self.from_users = from_users()
|
||||
|
||||
# Should we short-circuit? E.g. perform no check at all
|
||||
self._no_check = all(x is None for x in (
|
||||
self.chats, self.incoming, self.outgoing, self.pattern,
|
||||
|
|
Loading…
Reference in New Issue
Block a user