mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-06 05:00:23 +03:00
Merge faf2142122
into c6d821910e
This commit is contained in:
commit
7d5f0e5227
|
@ -235,12 +235,14 @@ class NewMessage(_EventBuilder):
|
||||||
super().__init__(chats=chats, blacklist_chats=blacklist_chats)
|
super().__init__(chats=chats, blacklist_chats=blacklist_chats)
|
||||||
self.incoming = incoming
|
self.incoming = incoming
|
||||||
self.outgoing = outgoing
|
self.outgoing = outgoing
|
||||||
if isinstance(pattern, str):
|
if pattern is None or utils.is_list_like(pattern):
|
||||||
self.pattern = re.compile(pattern).match
|
|
||||||
elif not pattern or callable(pattern):
|
|
||||||
self.pattern = pattern
|
self.pattern = pattern
|
||||||
|
elif isinstance(pattern, str):
|
||||||
|
self.pattern = [re.compile(pattern).match]
|
||||||
|
elif callable(pattern):
|
||||||
|
self.pattern = [pattern]
|
||||||
elif hasattr(pattern, 'match') and callable(pattern.match):
|
elif hasattr(pattern, 'match') and callable(pattern.match):
|
||||||
self.pattern = pattern.match
|
self.pattern = [pattern.match]
|
||||||
else:
|
else:
|
||||||
raise TypeError('Invalid pattern type given')
|
raise TypeError('Invalid pattern type given')
|
||||||
|
|
||||||
|
@ -300,8 +302,11 @@ class NewMessage(_EventBuilder):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.pattern:
|
if self.pattern:
|
||||||
match = self.pattern(event.message.message or '')
|
for pattern in self.pattern:
|
||||||
if not match:
|
match = pattern(event.message.message or '')
|
||||||
|
if match is not None:
|
||||||
|
break
|
||||||
|
else:
|
||||||
return
|
return
|
||||||
event.pattern_match = match
|
event.pattern_match = match
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user