From 70af0a7e6023befbdd0ee2791b2350ef7f50893f Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 4 Feb 2022 15:11:11 +0200 Subject: [PATCH] sfd --- files/helpers/const.py | 16 +++- files/routes/admin.py | 149 +++++++++++++++++++++++++++++++- files/routes/reporting.py | 15 +++- files/templates/submission.html | 4 +- 4 files changed, 173 insertions(+), 11 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index c1e2a355c..c4513ca44 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -100,16 +100,24 @@ SLURS = { } single_words = "|".join([slur.lower() for slur in SLURS.keys()]) -SLUR_REGEX = re.compile(rf"(?i)((?<=\s|>)|^)({single_words})((?=[\s<,.]|s[\s<,.])|$)", re.A) -def sub_matcher(match: re.Match): +SLUR_REGEX = re.compile(rf"(?i)((?<=\s|>)|^)({single_words})((?=[\s<,.]|s[\s<,.])|$)", re.A) +SLUR_REGEX_UPPER = re.compile(rf"((?<=\s|>)|^)({single_words.upper()})((?=[\s<,.]|s[\s<,.])|$)", re.A) + +def sub_matcher(match): return SLURS[match.group(0).lower()] -def censor_slurs(body: str, logged_user): - if not logged_user or logged_user.slurreplacer: body = SLUR_REGEX.sub(sub_matcher, body) +def sub_matcher_upper(match): + return SLURS[match.group(0).lower()].upper() + +def censor_slurs(body, logged_user): + if not logged_user or logged_user.slurreplacer: + body = SLUR_REGEX_UPPER.sub(sub_matcher_upper, body) + body = SLUR_REGEX.sub(sub_matcher, body) return body def torture_ap(body, username): + body = SLUR_REGEX_UPPER.sub(sub_matcher_upper, body) body = SLUR_REGEX.sub(sub_matcher, body) for k, l in AJ_REPLACEMENTS.items(): body = body.replace(k, l) body = re.sub('(^|\s|\n)(i|me) ', rf'\1@{username} ', body, re.I|re.A) diff --git a/files/routes/admin.py b/files/routes/admin.py index 846e9f4c8..183f9f146 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -35,6 +35,14 @@ def make_admin(v, username): if not user: abort(404) user.admin_level = 2 g.db.add(user) + + ma = ModAction( + kind="make_admin", + user_id=v.id, + target_user_id=user.id + ) + g.db.add(ma) + g.db.commit() return {"message": "User has been made admin!"} @@ -47,6 +55,14 @@ def remove_admin(v, username): if not user: abort(404) user.admin_level = 0 g.db.add(user) + + ma = ModAction( + kind="remove_admin", + user_id=v.id, + target_user_id=user.id + ) + g.db.add(ma) + g.db.commit() return {"message": "Admin removed!"} @@ -88,6 +104,13 @@ def distribute(v, comment): post.body += '\n\nclosed' g.db.add(post) + ma = ModAction( + kind="distribute", + user_id=v.id, + target_comment_id=cid + ) + g.db.add(ma) + g.db.commit() return {"message": f"Each winner has received {coinsperperson} coins!"} @@ -98,6 +121,13 @@ def revert_actions(v, username): user = get_user(username) if not user: abort(404) + ma = ModAction( + kind="revert", + user_id=v.id, + target_user_id=user.id + ) + g.db.add(ma) + cutoff = int(time.time()) - 86400 posts = [x[0] for x in g.db.query(ModAction.target_submission_id).filter(ModAction.user_id == user.id, ModAction.created_utc > cutoff, ModAction.kind == 'ban_post').all()] @@ -149,6 +179,13 @@ def club_allow(v, username): x.club_allowed = True g.db.add(x) + ma = ModAction( + kind="club_allow", + user_id=v.id, + target_user_id=u.id + ) + g.db.add(ma) + g.db.commit() return {"message": f"@{username} has been allowed into the {CC_TITLE}!"} @@ -169,6 +206,13 @@ def club_ban(v, username): u.club_allowed = False g.db.add(x) + ma = ModAction( + kind="club_ban", + user_id=v.id, + target_user_id=u.id + ) + g.db.add(ma) + g.db.commit() return {"message": f"@{username} has been kicked from the {CC_TITLE}. Deserved."} @@ -182,6 +226,14 @@ def make_meme_admin(v, username): if not user: abort(404) user.admin_level = 1 g.db.add(user) + + ma = ModAction( + kind="make_meme_admin", + user_id=v.id, + target_user_id=user.id + ) + g.db.add(ma) + g.db.commit() return {"message": "User has been made meme admin!"} @@ -195,6 +247,14 @@ def remove_meme_admin(v, username): if not user: abort(404) user.admin_level = 0 g.db.add(user) + + ma = ModAction( + kind="remove_meme_admin", + user_id=v.id, + target_user_id=user.id + ) + g.db.add(ma) + g.db.commit() return {"message": "Meme admin removed!"} @@ -238,6 +298,12 @@ def monthly(v): u.procoins += 50000 g.db.add(u) + ma = ModAction( + kind="monthly", + user_id=v.id + ) + g.db.add(ma) + g.db.commit() return {"message": "Monthly coins granted"} @@ -382,6 +448,13 @@ def disable_signups(v): def purge_cache(v): cache.clear() response = str(requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data='{"purge_everything":true}')) + + ma = ModAction( + kind="purge_cache", + user_id=v.id + ) + g.db.add(ma) + if response == "": return {"message": "Cache purged!"} return {"error": "Failed to purge cache."} @@ -454,6 +527,14 @@ def badge_grant_post(v): text = f"@{v.username} has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}" send_notification(user.id, text) + ma = ModAction( + kind="badge_grant", + user_id=v.id, + target_user_id=user.id, + _note=new_badge.name + ) + g.db.add(ma) + g.db.commit() return render_template("admin/badge_grant.html", v=v, badge_types=badges, msg="Badge granted!") @@ -483,6 +564,15 @@ def badge_remove_post(v): badge = user.has_badge(badge_id) if badge: g.db.delete(badge) + + ma = ModAction( + kind="badge_remove", + user_id=v.id, + target_user_id=user.id, + _note=badge.name + ) + g.db.add(ma) + g.db.commit() return render_template("admin/badge_remove.html", v=v, badge_types=badges, msg="Badge removed!") @@ -632,6 +722,14 @@ def admin_link_accounts(v): g.db.add(new_alt) + ma = ModAction( + kind="link_accounts", + user_id=v.id, + target_user_id=u1, + _note=f'with {u2}' + ) + g.db.add(ma) + g.db.commit() return redirect(f"{SITE_FULL}/admin/alt_votes?u1={g.db.query(User).get(u1).username}&u2={g.db.query(User).get(u2).username}") @@ -1056,11 +1154,22 @@ def api_distinguish_post(post_id, v): if post.author_id != v.id and v.admin_level < 2 : abort(403) - if post.distinguish_level: post.distinguish_level = 0 - else: post.distinguish_level = v.admin_level + if post.distinguish_level: + post.distinguish_level = 0 + kind = 'undistinguish_post' + else: + post.distinguish_level = v.admin_level + kind = 'distinguish_post' g.db.add(post) + ma = ModAction( + kind=kind, + user_id=v.id, + target_submission_id=post.id + ) + g.db.add(ma) + g.db.commit() if post.distinguish_level: return {"message": "Post distinguished!"} @@ -1082,6 +1191,13 @@ def sticky_post(post_id, v): else: post.stickied = v.username g.db.add(post) + ma=ModAction( + kind="pin_post", + user_id=v.id, + target_submission_id=post.id + ) + g.db.add(ma) + if v.id != post.author_id: send_repeatable_notification(post.author_id, f"@{v.username} has pinned your [post](/post/{post_id})!") @@ -1123,6 +1239,13 @@ def sticky_comment(cid, v): comment.is_pinned = v.username g.db.add(comment) + ma=ModAction( + kind="pin_comment", + user_id=v.id, + target_comment_id=comment.id + ) + g.db.add(ma) + if v.id != comment.author_id: message = f"@{v.username} has pinned your [comment]({comment.permalink})!" send_repeatable_notification(comment.author_id, message) @@ -1218,9 +1341,22 @@ def admin_distinguish_comment(c_id, v): if comment.author_id != v.id: abort(403) - comment.distinguish_level = 0 if comment.distinguish_level else v.admin_level + if comment.distinguish_level: + comment.distinguish_level = 0 + kind = 'distinguish_comment' + else: + comment.distinguish_level = v.admin_level + kind = 'undistinguish_comment' g.db.add(comment) + + ma = ModAction( + kind=kind, + user_id=v.id, + target_comment_id=comment.id + ) + g.db.add(ma) + g.db.commit() if comment.distinguish_level: return {"message": "Comment distinguished!"} @@ -1230,6 +1366,13 @@ def admin_distinguish_comment(c_id, v): @admin_level_required(2) def admin_dump_cache(v): cache.clear() + + ma = ModAction( + kind="dump_cache", + user_id=v.id + ) + g.db.add(ma) + return {"message": "Internal cache cleared."} diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 8dc950e02..07718c40b 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -66,13 +66,24 @@ def remove_report(report_fn, v): if report_fn.startswith('c'): report = g.db.query(CommentFlag).filter_by(id=int(report_fn.lstrip('c'))).one_or_none() + ma=ModAction( + kind="delete_report_comment", + user_id=v.id, + target_comment_id=report.comment_id + ) elif report_fn.startswith('p'): report = g.db.query(Flag).filter_by(id=int(report_fn.lstrip('p'))).one_or_none() - else: - return {"error": "Invalid report ID"}, 400 + ma=ModAction( + kind="delete_report_post", + user_id=v.id, + target_submission_id=report.post_id + ) + else: return {"error": "Invalid report ID"}, 400 g.db.delete(report) + g.db.add(ma) + g.db.commit() return {"message": "Removed report"} \ No newline at end of file diff --git a/files/templates/submission.html b/files/templates/submission.html index 36117afcc..313e445fa 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -502,9 +502,9 @@ {% if p.domain == "twitter.com" %} {{p.embed_url | safe}} {% if v and v.theme.split("_")[0] in ["light", "coffee", "4chan"] %} - + {% else %} - + {% endif %} {% elif p.domain in ['youtu.be','youtube.com'] and p.embed_url and p.embed_url.startswith('