From f0b51ed2c0a374fd3fc01d6ec151c574ee98193a Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 21 Jul 2023 17:27:45 +0300 Subject: [PATCH] make !jannies dynamic --- files/helpers/alerts.py | 30 +++++++++++++++++------------- files/helpers/sanitize.py | 2 ++ files/routes/groups.py | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 370fd693b..e99f7b502 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -164,28 +164,32 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None): if log_cost: log_cost.ping_cost = cost return 'everyone' + elif i.group(1) == 'jannies': + group = None + member_ids = set([x[0] for x in g.db.query(User.id).filter(User.admin_level > 0, User.id != AEVANN_ID).all()]) else: group = g.db.get(Group, i.group(1)) if not group: continue + member_ids = group.member_ids - members = group.member_ids - notify_users - v.all_twoway_blocks + members = member_ids - notify_users - v.all_twoway_blocks - notify_users.update(members) + notify_users.update(members) - if ghost or v.id not in group.member_ids: - if group.name == 'biofoids': mul = 20 - else: mul = 10 + if ghost or v.id not in member_ids: + if group and group.name == 'biofoids': mul = 20 + else: mul = 10 - cost += len(members) * mul - if cost > v.coins: - abort(403, f"You need {cost} coins to mention these ping groups!") + cost += len(members) * mul + if cost > v.coins: + abort(403, f"You need {cost} coins to mention these ping groups!") - if log_cost: - log_cost.ping_cost = cost + if log_cost: + log_cost.ping_cost = cost - for user in g.db.query(User).filter(User.id.in_(members)).all(): - user.pay_account('coins', mul) - g.db.add(user) + for user in g.db.query(User).filter(User.id.in_(members)).all(): + user.pay_account('coins', mul) + g.db.add(user) v.charge_account('coins', cost) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index d9f4896a3..22c9612c8 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -419,6 +419,8 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=False, count_emojis if name == 'everyone': return f'!{name}' + elif name == 'jannies': + return f'!{name}' elif g.db.get(Group, name): return f'!{name}' else: diff --git a/files/routes/groups.py b/files/routes/groups.py index f2342be1c..ff810c6aa 100644 --- a/files/routes/groups.py +++ b/files/routes/groups.py @@ -32,7 +32,7 @@ def create_group(v): if not valid_sub_regex.fullmatch(name): return redirect(f"/ping_groups?error=Name does not match the required format!") - if name == 'everyone' or g.db.get(Group, name): + if name in {'everyone', 'jannies'} or g.db.get(Group, name): return redirect(f"/ping_groups?error=This group already exists!") if not v.charge_account('combined', GROUP_COST)[0]: