Skip to content
Snippets Groups Projects
Verified Commit e5e96a1c authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Make regex API explicit in react_room_messages

compiled regexes are not hashable, so we cannot detect the type.
parent b37bd71c
No related branches found
No related tags found
No related merge requests found
......@@ -131,7 +131,7 @@ class Matrix:
room = self.get_dm_room(mxid)
return self.get_room_messages(room, from_, dir_, limit)
def react_room_messages(self, room, cases):
def react_room_messages(self, room, cases, regex=False):
"""Get room messages and trigger callbacks.
The cases argument takes a dictionary mapping strings or compiled regexs to callables.
......@@ -153,15 +153,15 @@ class Matrix:
if event["type"] == "m.room.message" and event["content"]["msgtype"] == "m.text":
message = event["content"]["body"]
for key_, func in cases.items():
if isinstance(key_, str):
if message.lower().strip() == key_.lower().strip():
matches.append(message)
func(message, event)
elif isinstance(key_, re.Pattern):
if regex:
finds = key_.findall(messaage)
if finds:
matches.append(message)
func(finds, event)
else:
if message.lower().strip() == key_.lower().strip():
matches.append(message)
func(message, event)
return matches
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment