import re from .config.const import * tranny = f':marseytrain:' trannie = f':!marseytrain:' troon = f':marseytrain2:' def replace_train_html(body): body = body.replace(tranny, ':marseytrain:') body = body.replace(trannie, ':!marseytrain:') body = body.replace(troon, ':marseytrain2:') return body 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 match_str.isupper(): return repl.upper() if match_str.istitle(): return repl.title() return repl def sub_matcher_slurs(match): return sub_matcher(match, SLURS_FOR_REPLACING) def sub_matcher_profanities(match): return sub_matcher(match, PROFANITIES_FOR_REPLACING) def censor_slurs_profanities(body, logged_user): if not body: return "" 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)

	return body