Allow access to events' pattern match (#654)

This commit is contained in:
Joscha Götzer 2018-03-01 00:15:30 +01:00 committed by Lonami
parent 3655df50dc
commit 3184641549

View File

@ -77,6 +77,8 @@ class _EventCommon(abc.ABC):
self._input_chat = None
self._chat = None
self.pattern_match = None
self.is_private = isinstance(chat_peer, types.PeerUser)
self.is_group = (
isinstance(chat_peer, (types.PeerChat, types.PeerChannel))
@ -251,8 +253,12 @@ class NewMessage(_EventBuilder):
return
if self.outgoing and not event.message.out:
return
if self.pattern and not self.pattern(event.message.message or ''):
return
if self.pattern:
match = self.pattern(event.message.message or '')
if not match:
return
event.pattern_match = match
return self._filter_event(event)