use regex for generating ban_reason link when banning users #67

Closed
Aevann wants to merge 1 commits from banreason into master
2 changed files with 4 additions and 2 deletions

View File

@ -119,6 +119,8 @@ knowledgebase_page_regex = re.compile("[a-zA-Z0-9_\-]+", flags=re.A)
html_title_regex = re.compile("<title>(.{1,200})</title>", flags=re.I)
ban_reason_link_regex = re.compile("^(\/(post|comment)\/[0-9]+)", flags=re.I)
def sub_matcher(match:re.Match, upper=False, replace_with:Union[dict[str, str], dict[str, List[str]]]=SLURS):
group_num = 0
match_str = match.group(group_num)

View File

@ -979,8 +979,8 @@ def ban_user(user_id, v):
reason = request.values.get("reason").strip()[:256]
reason = filter_emojis_only(reason)
if reason.startswith("/") and '\\' not in reason:
reason = f'<a href="{reason.split()[0]}">{reason}</a>'
if '\\' not in reason:
reason = ban_reason_link_regex.sub(r'<a href="\1">\1</a>', reason)
user.ban(admin=v, reason=reason, days=days)