summaryrefslogtreecommitdiff
path: root/src/lib/blacklist_matcher.py
blob: 0f28953869c099e1f4f0a61a2e0aee965dad0347 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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('|'))