forked from MarseyWorld/MarseyWorld
fix matches (PCRE uses weird 1 indexing)
parent
c6b1d90dd8
commit
118a58c104
|
@ -116,11 +116,11 @@ pronouns_regex = re.compile("([a-z]{1,5})/[a-z]{1,5}(/[a-z]{1,5})?", flags=re.A|
|
||||||
knowledgebase_page_regex = re.compile("[a-zA-Z0-9_\-]+", flags=re.A)
|
knowledgebase_page_regex = re.compile("[a-zA-Z0-9_\-]+", flags=re.A)
|
||||||
|
|
||||||
def sub_matcher(match:re.Match, upper=False, replace_with:Union[dict[str, str], dict[str, List[str]]]=SLURS):
|
def sub_matcher(match:re.Match, upper=False, replace_with:Union[dict[str, str], dict[str, List[str]]]=SLURS):
|
||||||
if match.group(0).startswith('<'):
|
group_num = 0 if len(match.groups()) == 0 else 1
|
||||||
return match.group(0)
|
if match.group(group_num).startswith('<'):
|
||||||
|
return match.group(group_num)
|
||||||
else:
|
else:
|
||||||
group = 1 if len(match.groups()) > 1 else 0
|
repl = replace_with[match.group(group_num).lower()]
|
||||||
repl = replace_with[match.group(group).lower()]
|
|
||||||
if not isinstance(repl, str):
|
if not isinstance(repl, str):
|
||||||
repl = random.choice(repl)
|
repl = random.choice(repl)
|
||||||
return repl if not upper or "<img" in repl else repl.upper()
|
return repl if not upper or "<img" in repl else repl.upper()
|
||||||
|
|
Loading…
Reference in New Issue