From 95938ee3ec9bf70308df72fb106a3b53bcec2f8f Mon Sep 17 00:00:00 2001 From: Aevann Date: Tue, 7 Feb 2023 04:34:11 +0200 Subject: [PATCH] make sure all comment links have #context --- files/classes/comment.py | 2 +- files/helpers/regex.py | 3 ++- files/routes/admin.py | 6 ++++-- files/routes/awards.py | 6 +++++- files/routes/comments.py | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index d061abc58..ff6333ecf 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -217,7 +217,7 @@ class Comment(Base): 'is_banned': bool(self.is_banned), 'deleted_utc': self.deleted_utc, 'is_nsfw': self.over_18, - 'permalink': f'/comment/{self.id}', + 'permalink': f'/comment/{self.id}#context', 'stickied': self.stickied, 'distinguish_level': self.distinguish_level, 'post_id': self.post.id if self.post else 0, diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 949be7a2d..fc489b10f 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -190,7 +190,8 @@ def command_regex_matcher(match, upper=False): result = f'Your roll: {result}' return match.group(1) + result -reason_regex = re.compile('(/(post|comment)/[0-9]+)', flags=re.A) +reason_regex_post = re.compile('(/post/[0-9]+)', flags=re.A) +reason_regex_comment = re.compile('(/comment/[0-9]+)', flags=re.A) discord_username_regex = re.compile("(\s|^|>).{2,32}#[0-9]{4}(?=[^0-9]|$)", flags=re.A) diff --git a/files/routes/admin.py b/files/routes/admin.py index f50296135..6c8cd1c99 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -902,7 +902,8 @@ def ban_user(id, v): reason = filter_emojis_only(reason) - reason = reason_regex.sub(r'\1', reason) + reason = reason_regex_post.sub(r'\1', reason) + reason = reason_regex_comment.sub(r'\1', reason) user.ban(admin=v, reason=reason, days=days) @@ -984,7 +985,8 @@ def agendaposter(id, v): reason = filter_emojis_only(reason) - reason = reason_regex.sub(r'\1', reason) + reason = reason_regex_post.sub(r'\1', reason) + reason = reason_regex_comment.sub(r'\1', reason) duration = "permanently" if days: diff --git a/files/routes/awards.py b/files/routes/awards.py index fbfdd0925..521f42884 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -243,8 +243,12 @@ def award_thing(v, thing_type, id): author.ban_reason = None send_repeatable_notification(author.id, "You have been unbanned!") elif kind == "grass": + link3 = f"/{thing_type}/{thing.id}" + if thing_type == 'comment': + link3 += '#context' + author.is_banned = AUTOJANNY_ID - author.ban_reason = f"grass award used by @{v.username} on /{thing_type}/{thing.id}" + author.ban_reason = f"grass award used by @{v.username} on {link3}" author.unban_utc = int(time.time()) + 30 * 86400 send_repeatable_notification(author.id, f"Your account has been banned permanently for {link}. You must [provide the admins](/contact) a timestamped picture of you touching grass/snow/sand/ass to get unbanned!") elif kind == "pin": diff --git a/files/routes/comments.py b/files/routes/comments.py index b1ca2066c..a2b369152 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -230,7 +230,7 @@ def comment(v:User): Comment.wall_user_id == post_target.id if not posting_to_submission else None, Comment.body_html == body_html ).first() - if existing: abort(409, f"You already made that comment: /comment/{existing.id}") + if existing: abort(409, f"You already made that comment: /comment/{existing.id}#context") execute_antispam_comment_check(body, v) execute_antispam_duplicate_comment_check(v, body_html)