From 81e19b1aed6d27050c0028a39370275edc07c93c Mon Sep 17 00:00:00 2001 From: TLSM Date: Mon, 30 May 2022 05:32:45 -0400 Subject: [PATCH] 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. --- files/classes/user.py | 1 + files/helpers/blackjack.py | 3 +++ files/helpers/slots.py | 3 +++ files/helpers/treasure.py | 8 +++++--- files/helpers/wrappers.py | 1 + files/routes/settings.py | 4 ++++ files/templates/header.html | 4 ++-- files/templates/settings_filters.html | 16 ++++++++++++++++ 8 files changed, 35 insertions(+), 5 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index fa1b7e543..839015367 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -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) diff --git a/files/helpers/blackjack.py b/files/helpers/blackjack.py index d560aad86..c0c753059 100644 --- a/files/helpers/blackjack.py +++ b/files/helpers/blackjack.py @@ -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) diff --git a/files/helpers/slots.py b/files/helpers/slots.py index c9083c49a..55a0c0078 100644 --- a/files/helpers/slots.py +++ b/files/helpers/slots.py @@ -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(): diff --git a/files/helpers/treasure.py b/files/helpers/treasure.py index a17f2f277..e432b2eab 100644 --- a/files/helpers/treasure.py +++ b/files/helpers/treasure.py @@ -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) diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index b57299d9e..f57601a08 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -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)) diff --git a/files/routes/settings.py b/files/routes/settings.py index e1ad2e761..2dd3b81a4 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -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' diff --git a/files/templates/header.html b/files/templates/header.html index 4a3378ad4..fad937881 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -89,7 +89,7 @@ {%- endif %} - {% if v and LOTTERY_ENABLED %} + {% if v and v.can_gamble and LOTTERY_ENABLED %} - {% if LOTTERY_ENABLED %} + {% if v.can_gamble and LOTTERY_ENABLED %}