From 8f7d05d62dbe36af394a74137ce3727faa618d05 Mon Sep 17 00:00:00 2001 From: TLSM Date: Mon, 18 Jul 2022 01:10:01 -0400 Subject: [PATCH] Refactor feature flags to dict. In anticipation of adding about a dozen more features flags to support work for LGB, PIN_ENABLED and PROCOINS_ENABLED have been moved to the FEATURES dict in const.py. More generally looking to create a unified interface for logically-related constants, perhaps to support e.g. later moving these settings from hardcoded constants to data. --- files/helpers/actions.py | 2 +- files/helpers/const.py | 15 ++++++++++----- files/helpers/jinja2.py | 7 ++++--- files/routes/admin.py | 2 +- files/routes/awards.py | 4 ++-- files/routes/comments.py | 4 ++-- files/templates/header.html | 4 ++-- files/templates/shop.html | 2 +- files/templates/userpage.html | 8 ++++---- 9 files changed, 27 insertions(+), 21 deletions(-) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index d150167a2..418a19a6c 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -152,7 +152,7 @@ def execute_snappy(post, v): if body.startswith('!slots'): check_for_slots_command(body, snappy, c) - if PIN_ENABLED and (body.startswith(':#marseypin:') or body.startswith(':#marseypin2:')): + if FEATURES['PINS'] and (body.startswith(':#marseypin:') or body.startswith(':#marseypin2:')): post.stickied = "Snappy" post.stickied_utc = int(time.time()) + 3600 diff --git a/files/helpers/const.py b/files/helpers/const.py index 9931ca6a4..47c0f3231 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -139,11 +139,14 @@ PERMS = { # Minimum admin_level to perform action. 'CONTENT_THREADS': 3, } +FEATURES = { + 'PROCOINS': True, + 'PINS': True, +} + EMOJI_MARSEYS = True EMOJI_SRCS = ['files/assets/emojis.json'] -PROCOINS_ENABLED = True -PIN_ENABLED = True PIN_LIMIT = 3 POST_RATE_LIMIT = '1/second;2/minute;10/hour;50/day' LOGGEDIN_ACTIVE_TIME = 15 * 60 @@ -287,7 +290,8 @@ elif SITE == 'watchpeopledie.co': PERMS['HOLE_CREATE'] = 2 PERMS['FLAGS_VISIBLE'] = 2 - PROCOINS_ENABLED = False + FEATURES['PROCOINS'] = False + HOLE_NAME = 'flair' HOLE_STYLE_FLAIR = True HOLE_REQUIRED = True @@ -305,10 +309,11 @@ elif SITE == 'lgbdropthet.com': PERMS['HOLE_CREATE'] = 3 PERMS['FLAGS_VISIBLE_REPORTER'] = 2 + FEATURES['PROCOINS'] = False + EMOJI_MARSEYS = False EMOJI_SRCS = ['files/assets/emojis.lgbdropthet.json'] - PROCOINS_ENABLED = False PFP_DEFAULT_MARSEY = False HOLE_NAME = 'community' @@ -758,7 +763,7 @@ if SITE == 'pcmemes.net': AWARDS_DISABLED.remove('ghost') elif SITE_NAME == 'WPD': AWARDS_DISABLED.remove('lootbox') -if not PROCOINS_ENABLED: +if not FEATURES['PROCOINS']: AWARDS_DISABLED.append('benefactor') AWARDS2 = {x: AWARDS[x] for x in AWARDS if x not in AWARDS_DISABLED} diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 03fc5b004..54b9b9686 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -53,8 +53,9 @@ def inject_constants(): "AUTOJANNY_ID":AUTOJANNY_ID, "PUSHER_ID":PUSHER_ID, "CC":CC, "CC_TITLE":CC_TITLE, "listdir":listdir, "MOOSE_ID":MOOSE_ID, "AEVANN_ID":AEVANN_ID, "PIZZASHILL_ID":PIZZASHILL_ID, "DEFAULT_COLOR":DEFAULT_COLOR, - "COLORS":COLORS, "time":time, + "COLORS":COLORS, "time":time, "PERMS": PERMS, "FEATURES": FEATURES, "HOLE_NAME": HOLE_NAME, "HOLE_STYLE_FLAIR": HOLE_STYLE_FLAIR, "HOLE_REQUIRED": HOLE_REQUIRED, "LOTTERY_ENABLED": LOTTERY_ENABLED, "GUMROAD_LINK": GUMROAD_LINK, - "DEFAULT_THEME": DEFAULT_THEME, "DESCRIPTION": DESCRIPTION, "PERMS": PERMS, - "PROCOINS_ENABLED": PROCOINS_ENABLED, "has_sidebar": has_sidebar, "has_logo": has_logo, "FP": FP, "NOTIF_MODACTION_JL_MIN": NOTIF_MODACTION_JL_MIN} + "DEFAULT_THEME": DEFAULT_THEME, "DESCRIPTION": DESCRIPTION, + "has_sidebar": has_sidebar, "has_logo": has_logo, + "FP": FP, "NOTIF_MODACTION_JL_MIN": NOTIF_MODACTION_JL_MIN} diff --git a/files/routes/admin.py b/files/routes/admin.py index d2c468812..c9e4040a8 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1196,7 +1196,7 @@ def api_distinguish_post(post_id, v): @app.post("/sticky/") @admin_level_required(2) def sticky_post(post_id, v): - if not PIN_ENABLED: + if not FEATURES['PINS']: abort(403) post = get_post(post_id) diff --git a/files/routes/awards.py b/files/routes/awards.py index 417eb03e1..3bd22e676 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -199,7 +199,7 @@ def award_thing(v, thing_type, id): if note: text += f" ({note})" notify_mod_action(v.id, text) elif kind == "pin": - if not PIN_ENABLED: + if not FEATURES['PINS']: abort(403) if thing.stickied and thing.stickied_utc: thing.stickied_utc += 3600 @@ -275,7 +275,7 @@ def award_thing(v, thing_type, id): author.fish = True badge_grant(badge_id=90, user=author) elif kind == "progressivestack": - if not PIN_ENABLED: + if not FEATURES['PINS']: abort(403) if author.progressivestack: author.progressivestack += 21600 else: author.progressivestack = int(time.time()) + 21600 diff --git a/files/routes/comments.py b/files/routes/comments.py index 39f8931fc..5db2cb83c 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -846,7 +846,7 @@ def undelete_comment(cid, v): @app.post("/pin_comment/") @auth_required def pin_comment(cid, v): - if not PIN_ENABLED: + if not FEATURES['PINS']: abort(403) comment = get_comment(cid, v=v) @@ -890,7 +890,7 @@ def unpin_comment(cid, v): @app.post("/mod_pin/") @auth_required def mod_pin(cid, v): - if not PIN_ENABLED: + if not FEATURES['PINS']: abort(403) comment = get_comment(cid, v=v) diff --git a/files/templates/header.html b/files/templates/header.html index d829e4dc6..ad085aba9 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -207,8 +207,8 @@
{{v.username}}
-
coins{{v.coins}}{% if not PROCOINS_ENABLED %} Coin{{ help.plural(v.coins) }}{% endif %}
- {% if PROCOINS_ENABLED %} +
coins{{v.coins}}{% if not FEATURES['PROCOINS'] %} Coin{{ help.plural(v.coins) }}{% endif %}
+ {% if FEATURES['PROCOINS'] %}
marseybux{{v.procoins}}
{% endif %}
diff --git a/files/templates/shop.html b/files/templates/shop.html index 2c9c97354..5c328b8d7 100644 --- a/files/templates/shop.html +++ b/files/templates/shop.html @@ -24,7 +24,7 @@
Coins spent by you: {{v.coins_spent}} coins
Lootboxes bought by you: {{v.lootboxes_bought}} lootbox{{'es' if v.lootboxes_bought != 1}}
Your current coins: {{v.coins}}
- {% if PROCOINS_ENABLED %} + {% if FEATURES['PROCOINS'] %}
Your current marseybux: {{v.procoins}}
{% endif %} diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 145635318..de1f01b98 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -121,7 +121,7 @@ {{u.coins}} coins   - {% if PROCOINS_ENABLED %} + {% if FEATURES['PROCOINS'] %} {{u.procoins}} marseybux   {% endif %} @@ -189,7 +189,7 @@ Get them help Gift coins - {% if PROCOINS_ENABLED %} + {% if FEATURES['PROCOINS'] %} Gift Marseybux {% endif %} @@ -432,7 +432,7 @@ {{u.coins}} coins   - {% if PROCOINS_ENABLED %} + {% if FEATURES['PROCOINS'] %} {{u.procoins}} marseybux   {% endif %} @@ -513,7 +513,7 @@ Message Get them help Gift coins - {% if PROCOINS_ENABLED %} + {% if FEATURES['PROCOINS'] %} Gift Marseybux {% endif %}