|
@@ -3,11 +3,9 @@ from typing import List
|
3
|
3
|
from million.model.message import Message
|
4
|
4
|
|
5
|
5
|
|
6
|
|
-def _wordFilter(msg: Message, regexs: List[str]) -> bool:
|
7
|
|
- return msg.content and any(
|
8
|
|
- re.search(rgx, msg.content, re.I) for rgx in regexs
|
9
|
|
- )
|
|
6
|
+def _wordFilter(msg: Message, words: List[str]) -> bool:
|
|
7
|
+ rgx = r"(\b"+ r'\b|\b'.join(words) + r"\b)"
|
|
8
|
+ return msg.content and re.search(rgx, msg.content, re.I)
|
10
|
9
|
|
11
|
10
|
def findWords(messages: List[Message], words: List[str]) -> List[Message]:
|
12
|
|
- r_words = [r"\b"+word+r"\b" for word in words]
|
13
|
|
- return filter(lambda m: _wordFilter(m, r_words), messages)
|
|
11
|
+ return filter(lambda m: _wordFilter(m, words), messages)
|