From 7ab046474fc1189b0e0b99c3587d661bc389316c Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 11 Aug 2023 16:38:49 +0300 Subject: [PATCH] disallow !followers ping in posts --- files/helpers/alerts.py | 4 +++- files/routes/posts.py | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index cc0b90015..94dcf3486 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -120,7 +120,7 @@ def add_notif(cid, uid, text, pushnotif_url=''): push_notif({uid}, 'New notification', text, pushnotif_url) -def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None): +def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None, followers_ping=True): # Restrict young accounts from generating notifications if v.age < NOTIFICATION_SPAM_AGE_THRESHOLD: return set() @@ -165,6 +165,8 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None): group = None member_ids = set([x[0] for x in g.db.query(User.id).filter(User.admin_level > 0, User.id != AEVANN_ID)]) elif i.group(1) == 'followers': + if not followers_ping: + abort(403, f"You can't use !followers in posts!") group = None member_ids = set([x[0] for x in g.db.query(Follow.user_id).filter_by(target_id=v.id)]) else: diff --git a/files/routes/posts.py b/files/routes/posts.py index 59949821f..86eaf916c 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -58,7 +58,7 @@ def publish(pid, v): p.created_utc = int(time.time()) g.db.add(p) - notify_users = NOTIFY_USERS(f'{p.title} {p.body}', v, ghost=p.ghost, log_cost=p) + notify_users = NOTIFY_USERS(f'{p.title} {p.body}', v, ghost=p.ghost, log_cost=p, followers_ping=False) if notify_users: cid, text = notif_comment2(p) @@ -602,7 +602,7 @@ def submit_post(v, sub=None): abort(415) if not p.private: - notify_users = NOTIFY_USERS(f'{title} {body}', v, ghost=p.ghost, log_cost=p) + notify_users = NOTIFY_USERS(f'{title} {body}', v, ghost=p.ghost, log_cost=p, followers_ping=False) if notify_users: cid, text = notif_comment2(p) @@ -978,7 +978,7 @@ def edit_post(pid, v): if not p.private: - notify_users = NOTIFY_USERS(f'{title} {body}', v, oldtext=f'{p.title} {p.body}', ghost=p.ghost, log_cost=p) + notify_users = NOTIFY_USERS(f'{title} {body}', v, oldtext=f'{p.title} {p.body}', ghost=p.ghost, log_cost=p, followers_ping=False) if notify_users: cid, text = notif_comment2(p) if notify_users == 'everyone':