From ccf6ccd468a859777e96ccf2f76acfcea90661e8 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 11 Mar 2023 11:50:29 +0200 Subject: [PATCH] same as last commit --- files/classes/user.py | 3 +-- files/helpers/sanitize.py | 25 +++++++++++++++++++++++-- files/routes/notifications.py | 2 +- files/routes/users.py | 2 ++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 59b7e9721..97fcfc967 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -1027,7 +1027,6 @@ class User(Base): return False if other.sub and not cls.can_see(user, other.subr): return False - else: if other.parent_submission: return cls.can_see(user, other.post) @@ -1039,7 +1038,7 @@ class User(Base): if other.top_comment.author_id == user.id: return True return user.admin_level >= PERMS['VIEW_MODMAIL'] if other.sentto != user.id: - return False + return user.admin_level >= PERMS['BLACKJACK_NOTIFICATIONS'] elif isinstance(other, Sub): if other.name == 'chudrama': return bool(user) and user.can_see_chudrama if other.name in {'countryclub','splash_mountain'}: return bool(user) and user.can_see_countryclub diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index aa8184e33..d3605f23f 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -193,8 +193,6 @@ def execute_blackjack(v, target, body, type): n = Notification(comment_id=target.id, user_id=id) g.db.add(n) - push_notif(notified_ids, f'Blackjack by @{v.username}', target.body, target) - extra_info = None if extra_info: @@ -202,6 +200,29 @@ def execute_blackjack(v, target, body, type): send_repeatable_notification(id, f"Blackjack by @{v.username}: {extra_info}") return True +def execute_anti_grooming(v, c, u): + if 'discord' not in c.body and 'groomercord' not in c.body or v.shadowbanned: + return + + v.shadowbanned = AUTOJANNY_ID + + ma = ModAction( + kind="shadowban", + user_id=AUTOJANNY_ID, + target_user_id=v.id, + _note=f'reason: "Grooming @{u.username}"' + ) + g.db.add(ma) + + v.ban_reason = f"Grooming @{u.username}" + g.db.add(v) + + notified_ids = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['BLACKJACK_NOTIFICATIONS'])] + + for id in notified_ids: + n = Notification(comment_id=c.id, user_id=id) + g.db.add(n) + def render_emoji(html, regexp, golden, marseys_used, b=False): emojis = list(regexp.finditer(html)) captured = set() diff --git a/files/routes/notifications.py b/files/routes/notifications.py index dde238529..199332355 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -303,7 +303,7 @@ def notifications(v:User): comments = g.db.query(Comment, Notification).join(Notification.comment).join(Comment.author).filter( Notification.user_id == v.id, - or_(Comment.sentto == None, Comment.sentto == MODMAIL_ID), + or_(Comment.sentto == None, Comment.sentto != v.id), not_(and_(Comment.sentto == MODMAIL_ID, User.is_muted)), ) diff --git a/files/routes/users.py b/files/routes/users.py index 62ee84d0e..fe61c2bd2 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -536,6 +536,7 @@ def message2(v:User, username:str): g.db.flush() execute_blackjack(v, c, c.body_html, 'message') execute_under_siege(v, c, c.body_html, 'message') + execute_anti_grooming(v, c, user) c.top_comment_id = c.id if user.id not in bots: @@ -609,6 +610,7 @@ def messagereply(v:User): g.db.flush() execute_blackjack(v, c, c.body_html, 'message') execute_under_siege(v, c, c.body_html, 'message') + execute_anti_grooming(v, c, user) if user_id and user_id not in {v.id, MODMAIL_ID} | bots: notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=user_id).one_or_none()