diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 9ad76172f..8c73f689d 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -186,3 +186,5 @@ def command_regex_matcher(match, upper=False): color = tuple(choices(range(256), k=3)) result = f'Your roll: {result}' return match.group(1) + result + +reason_regex = re.compile('(/(post|comment)/[0-9]+)', flags=re.A) diff --git a/files/routes/admin.py b/files/routes/admin.py index e8fd20217..8d7800cf4 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1003,11 +1003,10 @@ def ban_user(user_id, v): if not reason: abort(400, "You need to submit a reason for banning!") - if reason.startswith("/") and '\\' not in reason: - reason = f'{reason}' - reason = filter_emojis_only(reason) + reason = reason_regex.sub(r'\1', reason) + user.ban(admin=v, reason=reason, days=days) if request.values.get("alts"): @@ -1071,11 +1070,11 @@ def agendaposter(user_id, v): pass reason = request.values.get("reason", "").strip() - if reason and reason.startswith("/") and '\\' not in reason: - reason = f'{reason}' reason = filter_emojis_only(reason) + reason = reason_regex.sub(r'\1', reason) + duration = "permanently" if days: user.agendaposter = int(time.time()) + (days * 86400)