diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/__init__.py | 1 | ||||
-rw-r--r-- | src/lib/blacklist_matcher.py | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/__init__.py b/src/lib/__init__.py new file mode 100644 index 0000000..4c7efe4 --- /dev/null +++ b/src/lib/__init__.py @@ -0,0 +1 @@ +from src.lib.blacklist_matcher import contains_forbidden_term diff --git a/src/lib/blacklist_matcher.py b/src/lib/blacklist_matcher.py new file mode 100644 index 0000000..0f28953 --- /dev/null +++ b/src/lib/blacklist_matcher.py @@ -0,0 +1,19 @@ +import re +from functools import cache +from config import user_config + + +def contains_forbidden_term(comment): + matcher = build_matcher() + + return matcher.search(comment) is not None + + +@cache +def build_matcher(): + regex_string = '' + + for word in user_config['Env']['blacklist']: + regex_string += f"{word}|" + + return re.compile(regex_string.removesuffix('|')) |