import re from typing import List from million.model.message import Message def _wordFilter(msg: Message, regexs: List[str]) -> bool: return msg.content and any( re.search(rgx, msg.content, re.I) for rgx in regexs ) def findWords(messages: List[Message], words: List[str]) -> List[Message]: r_words = [r"\b"+word+r"\b" for word in words] return filter(lambda m: _wordFilter(m, r_words), messages)