mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-06 21:20:22 +03:00
Changed events.NewMessage to accept a list of patterns instead of just 1
This commit is contained in:
parent
95f368201e
commit
071ebcb4ef
|
@ -236,11 +236,13 @@ class NewMessage(_EventBuilder):
|
||||||
self.incoming = incoming
|
self.incoming = incoming
|
||||||
self.outgoing = outgoing
|
self.outgoing = outgoing
|
||||||
if isinstance(pattern, str):
|
if isinstance(pattern, str):
|
||||||
self.pattern = re.compile(pattern).match
|
self.pattern = [re.compile(pattern).match]
|
||||||
elif not pattern or callable(pattern):
|
elif isinstance(pattern, (list, tuple)):
|
||||||
self.pattern = pattern
|
self.pattern = pattern
|
||||||
|
elif not pattern or 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