mirror of
https://github.com/maubot/maubot.git
synced 2024-10-01 01:06:10 -04:00
Fix passive command matching and add regex flag args
This commit is contained in:
parent
76c9c40844
commit
a57df919f5
@ -326,10 +326,17 @@ def argument(name: str, label: str = None, *, required: bool = True, matches: Op
|
||||
|
||||
def passive(regex: Union[str, Pattern], *, msgtypes: Sequence[MessageType] = (MessageType.TEXT,),
|
||||
field: Callable[[MaubotMessageEvent], str] = lambda evt: evt.content.body,
|
||||
event_type: EventType = EventType.ROOM_MESSAGE, multiple: bool = False
|
||||
event_type: EventType = EventType.ROOM_MESSAGE, multiple: bool = False,
|
||||
case_insensitive: bool = False, multiline: bool = False, dot_all: bool = False
|
||||
) -> PassiveCommandHandlerDecorator:
|
||||
if not isinstance(regex, Pattern):
|
||||
regex = re.compile(regex)
|
||||
if case_insensitive:
|
||||
regex.flags |= re.IGNORECASE
|
||||
if multiline:
|
||||
regex.flags |= re.MULTILINE
|
||||
if dot_all:
|
||||
regex.flags |= re.DOTALL
|
||||
|
||||
def decorator(func: CommandHandlerFunc) -> CommandHandlerFunc:
|
||||
combine = None
|
||||
@ -352,7 +359,7 @@ def passive(regex: Union[str, Pattern], *, msgtypes: Sequence[MessageType] = (Me
|
||||
val = [(data[match.pos:match.endpos], *match.groups())
|
||||
for match in regex.finditer(data)]
|
||||
else:
|
||||
match = regex.match(data)
|
||||
match = regex.search(data)
|
||||
if match:
|
||||
val = (data[match.pos:match.endpos], *match.groups())
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user