import re from .config.const import * tranny = f':marseytrain:' trannie = f':!marseytrain:' troon = f':marseytrain2:' #DON'T ADD ANY FILTERS WITH ' OR ", VECTOR FOR HTML INJECTION SLURS = { 'tranny': tranny, 'trannie': trannie, 'troon': troon, '(?]*>|{slur_single_words}", flags=re.I|re.A) profanity_regex = re.compile(f"<[^>]*>|{profanity_single_words}", flags=re.I|re.A) SLURS_FOR_REPLACING = {} for k, val in SLURS.items(): newkey = k.split('(?!')[0] if ')' in newkey: newkey = newkey.split(')')[1] SLURS_FOR_REPLACING[newkey] = val PROFANITIES_FOR_REPLACING = {} for k, val in PROFANITIES.items(): newkey = k.split('(?!')[0] if ')' in newkey: newkey = newkey.split(')')[1] PROFANITIES_FOR_REPLACING[newkey] = val def sub_matcher(match, X_FOR_REPLACING): group_num = 0 match_str = match.group(group_num) if match_str.startswith('<'): return match_str else: repl = X_FOR_REPLACING[match_str.lower()] if "' in body or '' in body: return body if not logged_user or logged_user == 'chat' or logged_user.slurreplacer: body = slur_regex.sub(sub_matcher_slurs, body) if SITE_NAME == 'rDrama': if not logged_user or logged_user == 'chat' or logged_user.profanityreplacer: body = profanity_regex.sub(sub_matcher_profanities, body) if is_plain: body = body.replace(tranny, ':marseytrain:') body = body.replace(trannie, ':!marseytrain:') body = body.replace(troon, ':marseytrain2:') return body