From f78cd322d1ce0d0d01cb7493f1cab58e8b8f6d0f Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 22 Mar 2023 23:39:25 +0200 Subject: [PATCH] much better chud award logic --- files/classes/comment.py | 5 ----- files/classes/submission.py | 5 ----- files/classes/user.py | 5 ----- files/helpers/sanitize.py | 12 ++++++++++++ files/routes/admin.py | 4 ++-- files/routes/comments.py | 4 ++-- files/routes/posts.py | 4 ++-- files/templates/modals/award.html | 4 ++-- 8 files changed, 20 insertions(+), 23 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 9432f5119..7b1167bed 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -454,8 +454,3 @@ class Comment(Base): body += '' return body - - @property - @lazy - def complies_with_chud(self): - return self.author.phrase_regex.search(self.body_html.lower()) diff --git a/files/classes/submission.py b/files/classes/submission.py index a5619f0ce..c7a6cb8b9 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -359,8 +359,3 @@ class Submission(Base): @lazy def active_flags(self, v): return len(self.filtered_flags(v)) - - @property - @lazy - def complies_with_chud(self): - return self.author.phrase_regex.search(self.body_html.lower()) diff --git a/files/classes/user.py b/files/classes/user.py index 890cbaa8c..a09ea548c 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -1211,8 +1211,3 @@ class User(Base): def can_see_my_shit(self): v = g.v return not self.shadowbanned or (v and (v.id == self.id or v.can_see_shadowbanned)) - - @property - @lazy - def phrase_regex(self): - return re.compile(f"

[^<>]*{self.agendaposter_phrase}[^<>]*<\/p>(?![^<]*<\/)") diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 54775231f..833ff14fb 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -617,3 +617,15 @@ def validate_css(css): return False, f"The domain '{domain}' is not allowed, please use one of these domains\n\n{approved_embed_hosts}." return True, "" + + +def complies_with_chud(obj): + soup=BeautifulSoup(obj.body_html.lower(), 'lxml') + + tags = soup.html.body.find_all('p', recursive=False) + + for x in tags: + if obj.author.agendaposter_phrase in str(x.find(text=True, recursive=False)): + return True + + return False diff --git a/files/routes/admin.py b/files/routes/admin.py index f12746758..43be204f6 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1306,7 +1306,7 @@ def remove_post(post_id, v): def approve_post(post_id, v): post = get_post(post_id) - if post.author.id == v.id and post.author.agendaposter and post.sub != 'chudrama' and not post.complies_with_chud: + if post.author.id == v.id and post.author.agendaposter and post.sub != 'chudrama' and not complies_with_chud(post): abort(400, "You can't bypass the chud award!") if post.is_banned: @@ -1540,7 +1540,7 @@ def remove_comment(c_id, v): def approve_comment(c_id, v): comment = get_comment(c_id) - if comment.author.id == v.id and comment.author.agendaposter and not (comment.parent_submission and comment.post.sub == 'chudrama') and not comment.complies_with_chud: + if comment.author.id == v.id and comment.author.agendaposter and not (comment.parent_submission and comment.post.sub == 'chudrama') and not complies_with_chud(comment): abort(400, "You can't bypass the chud award!") if comment.is_banned: diff --git a/files/routes/comments.py b/files/routes/comments.py index e716d07f8..0efe3a805 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -279,7 +279,7 @@ def comment(v:User): if c.level == 1: c.top_comment_id = c.id else: c.top_comment_id = parent.top_comment_id - if post_target.id not in ADMIGGER_THREADS and v.agendaposter and not v.marseyawarded and not (posting_to_submission and post_target.sub == 'chudrama') and not c.complies_with_chud: + if post_target.id not in ADMIGGER_THREADS and v.agendaposter and not v.marseyawarded and not (posting_to_submission and post_target.sub == 'chudrama') and not complies_with_chud(c): c.is_banned = True c.ban_reason = "AutoJanny" g.db.add(c) @@ -674,7 +674,7 @@ def edit_comment(cid, v): execute_blackjack(v, c, c.body, "comment") execute_under_siege(v, c, c.body, "comment") - if not (c.parent_submission and c.post.id in ADMIGGER_THREADS) and v.agendaposter and not v.marseyawarded and not (c.parent_submission and c.post.sub == 'chudrama') and not c.complies_with_chud: + if not (c.parent_submission and c.post.id in ADMIGGER_THREADS) and v.agendaposter and not v.marseyawarded and not (c.parent_submission and c.post.sub == 'chudrama') and not complies_with_chud(c): abort(403, f'You have to include "{v.agendaposter_phrase}" in your comment!') diff --git a/files/routes/posts.py b/files/routes/posts.py index a2c6e106a..8d0a7d018 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -656,7 +656,7 @@ def submit_post(v:User, sub=None): for x in notify_users: add_notif(cid, x, text, pushnotif_url=p.permalink) - if v.agendaposter and not v.marseyawarded and sub != 'chudrama' and not p.complies_with_chud: + if v.agendaposter and not v.marseyawarded and sub != 'chudrama' and not complies_with_chud(p): p.is_banned = True p.ban_reason = "AutoJanny" @@ -1041,7 +1041,7 @@ def edit_post(pid, v): p.body_html = body_html - if v.id == p.author_id and v.agendaposter and not v.marseyawarded and p.sub != 'chudrama' and not p.complies_with_chud: + if v.id == p.author_id and v.agendaposter and not v.marseyawarded and p.sub != 'chudrama' and not complies_with_chud(p): abort(403, f'You have to include "{v.agendaposter_phrase}" in your post!') diff --git a/files/templates/modals/award.html b/files/templates/modals/award.html index 12e235e22..366ce7d65 100644 --- a/files/templates/modals/award.html +++ b/files/templates/modals/award.html @@ -44,8 +44,8 @@ "Black lives matter", "Black trans lives matter", "The future is female", - "Saying this as a feminist ally", - "Stand with israel", + "I say this as a feminist ally", + "I stand with israel", "Vaccines work", "Trans women are women", "Furry rights are human rights",