Add can_gamble user setting.

Users now have a toggleable can_gamble setting which disables their
ability to use all chance-based gains on the site: viz. slots,
blackjack, the lottery, and treasure chests.

This only applies on invocation of commands that start gambling
games, so it should cause no bugs when toggled with e.g. active
blackjack games.

This was added for the benefit of users with actual problems with
gambling, be they past addiction or religious conviction. All future
gambling features are humbly requested to respect it.
master
Snakes 2022-05-30 05:32:45 -04:00
parent 470a3c76f5
commit 81e19b1aed
8 changed files with 35 additions and 5 deletions

View File

@ -127,6 +127,7 @@ class User(Base):
original_username = deferred(Column(String))
referred_by = Column(Integer, ForeignKey("users.id"))
subs_created = Column(Integer, default=0)
can_gamble = Column(Boolean, default=True)
currently_held_lottery_tickets = Column(Integer, default=0)
total_held_lottery_tickets = Column(Integer, default=0)
total_lottery_winnings = Column(Integer, default=0)

View File

@ -51,6 +51,9 @@ def format_all(player_hand, dealer_hand, deck, status, wager, kind, is_insured=0
def check_for_blackjack_commands(in_text, from_user, from_comment):
if not from_user.can_gamble:
return
for command_word in (coins_command_word, marseybux_command_word):
currency_prop = "coins" if command_word == coins_command_word else "procoins"
currency_value = getattr(from_user, currency_prop, 0)

View File

@ -19,6 +19,9 @@ def shuffle(stuff):
return stuff
def check_for_slots_command(in_text, from_user, from_comment):
if not from_user.can_gamble:
return
in_text = in_text.lower()
if command_word in in_text:
for word in in_text.split():

View File

@ -10,6 +10,11 @@ standard_max = 100
lotterizer_rate = 33
def check_for_treasure(in_text, from_comment):
user = from_comment.author
if not user.can_gamble:
return
if '!slots' not in in_text and '!blackjack' not in in_text and '!wordle' not in in_text:
seed = randint(1, 1000)
is_special = seed == 1000
@ -21,14 +26,11 @@ def check_for_treasure(in_text, from_comment):
elif is_standard:
amount = randint(standard_min, standard_max)
if randint(1, 100) > 90:
user = from_comment.author
if amount > user.coins: amount = user.coins
amount = -amount
if amount != 0:
user = from_comment.author
if amount > 0:
active_lottery = get_active_lottery()
lottery_tickets_seed = randint(1, 100)

View File

@ -144,6 +144,7 @@ def lottery_required(f):
v = get_logged_in_user()
if not LOTTERY_ENABLED: abort(404)
if v and not v.can_gamble: abort(403)
return make_response(f(v=v))

View File

@ -83,6 +83,10 @@ def settings_profile_post(v):
updated = True
v.newtabexternal = request.values.get("newtabexternal") == 'true'
elif request.values.get("can_gamble", v.can_gamble) != v.can_gamble:
updated = True
v.can_gamble = request.values.get("can_gamble") == 'true'
elif request.values.get("nitter", v.nitter) != v.nitter:
updated = True
v.nitter = request.values.get("nitter") == 'true'

View File

@ -89,7 +89,7 @@
<a class="mobile-nav-icon d-md-none" href="/chat"><i class="fas fa-messages align-middle text-gray-500 black"></i></a>
{%- endif %}
{% if v and LOTTERY_ENABLED %}
{% if v and v.can_gamble and LOTTERY_ENABLED %}
<span data-bs-toggle="tooltip" data-bs-placement="bottom" title="Lottershe">
<a
href="#"
@ -141,7 +141,7 @@
<a class="nav-link" href="/leaderboard" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Leaderboard"><i class="fas fa-trophy"></i></a>
</li>
{% if LOTTERY_ENABLED %}
{% if v.can_gamble and LOTTERY_ENABLED %}
<li class="nav-item d-flex align-items-center justify-content-center text-center mx-1">
<span
data-bs-toggle="tooltip"

View File

@ -145,6 +145,22 @@
</div>
<h2 class="h5">Gambling</h2>
<div class="settings-section rounded">
<div class="d-lg-flex border-bottom">
<div class="title w-lg-25">
<label for="can_gamble">Can Gamble</label>
</div>
<div class="body w-lg-100">
<div class="custom-control custom-switch">
<input autocomplete="off" type="checkbox" class="custom-control-input" id="can_gamble" name="can_gamble"{% if v.can_gamble %} checked{% endif %} onchange="post_toast(this,'/settings/profile?can_gamble='+document.getElementById('can_gamble').checked);">
<label class="custom-control-label" for="can_gamble"></label>
</div>
<span class="text-small-extra text-muted">Disable to prevent use of blackjack, slots, treasure chests, and the lottery.</span>
</div>
</div>
</div>
<h2 class="h5">Twitter Links</h2>