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.
remotes/1693045480750635534/spooky-22
Snakes 2022-07-18 01:10:01 -04:00
parent 76d925f1ba
commit 8f7d05d62d
Signed by: Snakes
GPG Key ID: E745A82778055C7E
9 changed files with 27 additions and 21 deletions

View File

@ -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

View File

@ -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}

View File

@ -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}

View File

@ -1196,7 +1196,7 @@ def api_distinguish_post(post_id, v):
@app.post("/sticky/<post_id>")
@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)

View File

@ -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

View File

@ -846,7 +846,7 @@ def undelete_comment(cid, v):
@app.post("/pin_comment/<cid>")
@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/<cid>")
@auth_required
def mod_pin(cid, v):
if not PIN_ENABLED:
if not FEATURES['PINS']:
abort(403)
comment = get_comment(cid, v=v)

View File

@ -207,8 +207,8 @@
</div>
<div class="text-left pl-2">
<div style="color: #{{v.namecolor}}" class="text-small font-weight-bold" id="header--username"><span {% if v.patron %}class="patron" style="background-color:#{{v.namecolor}}"{% endif %}>{{v.username}}</span></div>
<div class="header--currency"><img alt="coins" class="mr-1 ml-1" data-bs-toggle="tooltip" data-bs-placement="bottom" src="{{asset_siteimg('coins.webp')}}" title="coins" aria-label="coins"><span id="user-coins-amount">{{v.coins}}</span>{% if not PROCOINS_ENABLED %} Coin{{ help.plural(v.coins) }}{% endif %}</div>
{% if PROCOINS_ENABLED %}
<div class="header--currency"><img alt="coins" class="mr-1 ml-1" data-bs-toggle="tooltip" data-bs-placement="bottom" src="{{asset_siteimg('coins.webp')}}" title="coins" aria-label="coins"><span id="user-coins-amount">{{v.coins}}</span>{% if not FEATURES['PROCOINS'] %} Coin{{ help.plural(v.coins) }}{% endif %}</div>
{% if FEATURES['PROCOINS'] %}
<div class="header--currency"><img alt="marseybux" class="mr-1 ml-1" data-bs-toggle="tooltip" data-bs-placement="bottom" src="/i/marseybux.webp?v=2000" title="Marseybux" aria-label="Marseybux"><span id="user-bux-amount">{{v.procoins}}</span></div>
{% endif %}
</div>

View File

@ -24,7 +24,7 @@
<h5 class="mt-4">Coins spent by you: {{v.coins_spent}} coins</h5>
<h5 class="mt-4">Lootboxes bought by you: {{v.lootboxes_bought}} lootbox{{'es' if v.lootboxes_bought != 1}}</h5>
<h5 class="mt-4">Your current coins: {{v.coins}}</h5>
{% if PROCOINS_ENABLED %}
{% if FEATURES['PROCOINS'] %}
<h5 class="mt-4">Your current marseybux: {{v.procoins}}</h3>
{% endif %}
</header>

View File

@ -121,7 +121,7 @@
<span id="profile-coins-amount">{{u.coins}}</span>
<img alt="coins" class="ml-1 mb-1" data-bs-toggle="tooltip" data-bs-placement="bottom" title="coins" height="20" src="{{asset_siteimg('coins.webp')}}">&nbsp;&nbsp;
{% if PROCOINS_ENABLED %}
{% if FEATURES['PROCOINS'] %}
<span id="profile-bux-amount">{{u.procoins}}</span>
<img alt="marseybux" class="ml-1 mb-1" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Marseybux" height="20" width="46" src="/i/marseybux.webp?v=2000">&nbsp;&nbsp;
{% endif %}
@ -189,7 +189,7 @@
<a class="btn btn-primary" role="button" onclick="post_toast(this,'/@{{u.username}}/suicide')">Get them help</a>
<a class="btn btn-primary" role="button" onclick="toggleElement('coin-transfer', 'coin-transfer-amount')">Gift coins</a>
{% if PROCOINS_ENABLED %}
{% if FEATURES['PROCOINS'] %}
<a class="btn btn-primary" role="button" onclick="toggleElement('bux-transfer', 'bux-transfer-amount')">Gift Marseybux</a>
{% endif %}
@ -432,7 +432,7 @@
<span id="profile-coins-amount-mobile" class="font-weight-bold">{{u.coins}}</span>
<img alt="coins" class="ml-1 mb-1" data-bs-toggle="tooltip" data-bs-placement="bottom" title="coins" height="15" src="{{asset_siteimg('coins.webp')}}">&nbsp;&nbsp;
{% if PROCOINS_ENABLED %}
{% if FEATURES['PROCOINS'] %}
<span id="profile-bux-amount-mobile" class="font-weight-bold">{{u.procoins}}</span>
<img alt="marseybux" class="ml-1 mb-1" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Marseybux" height="15" width="35" src="/i/marseybux.webp?v=2000">&nbsp;&nbsp;
{% endif %}
@ -513,7 +513,7 @@
<a class="btn btn-primary" role="button" onclick="toggleElement('message-mobile', 'input-message-mobile')">Message</a>
<a class="btn btn-primary" role="button" onclick="post_toast(this,'/@{{u.username}}/suicide')">Get them help</a>
<a class="btn btn-primary" role="button" onclick="toggleElement('coin-transfer-mobile', 'coin-transfer-amount-mobile')">Gift coins</a>
{% if PROCOINS_ENABLED %}
{% if FEATURES['PROCOINS'] %}
<a class="btn btn-primary" role="button" onclick="toggleElement('bux-transfer-mobile', 'bux-transfer-amount-mobile')">Gift Marseybux</a>
{% endif %}