diff --git a/files/classes/comment.py b/files/classes/comment.py index e7c2fcc6a..25c3a89f0 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -64,6 +64,8 @@ class Comment(Base): ban_reason = Column(String) wordle_result = Column(String) treasure_amount = Column(String) + slots_result = Column(String) + casino_game_id = Column(Integer, ForeignKey("casino_games.id")) oauth_app = relationship("OauthApp") post = relationship("Submission", back_populates="comments") @@ -73,6 +75,7 @@ class Comment(Base): awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", back_populates="comment") flags = relationship("CommentFlag", order_by="CommentFlag.created_utc") options = relationship("CommentOption", order_by="CommentOption.id") + casino_game = relationship("Casino_Game") def __init__(self, *args, **kwargs): if "created_utc" not in kwargs: diff --git a/files/helpers/slots.py b/files/helpers/slots.py index 426c7df96..8ece9a6da 100644 --- a/files/helpers/slots.py +++ b/files/helpers/slots.py @@ -45,6 +45,7 @@ def casino_slot_pull(gambler, wager_value, currency): casino_game.kind = 'slots' casino_game.game_state = json.dumps(game_state) g.db.add(casino_game) + g.db.flush() return casino_game.id, casino_game.game_state else: diff --git a/files/routes/comments.py b/files/routes/comments.py index d206b7e75..20d573a05 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -368,6 +368,35 @@ def comment(v): parent_post.comment_count += 1 g.db.add(parent_post) + + if FEATURES['GAMBLING'] and '!slots' in c.body: + if v.rehab: + abort(403, "You are under Rehab award effect!") + + if '!slotsmb' in c.body: + command_word = '!slotsmb' + currency = 'procoins' + else: + command_word = '!slots' + currency = 'coins' + + wager = c.body.split(command_word)[1].split()[0] + + try: + wager = int(wager) + except: + abort(400, "Invalid wager.") + + if wager < 100: + abort(400, f"Wager must be 100 {currency} or more") + + if (currency == "coins" and wager > v.coins) or (currency == "procoins" and wager > v.procoins): + abort(400, f"Not enough {currency} to make that bet") + + game_id, game_state = casino_slot_pull(v, wager, currency) + + c.casino_game_id = game_id + g.db.flush() if v.client: return c.json diff --git a/files/templates/comments.html b/files/templates/comments.html index 7252479b6..5d0e199a9 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -202,6 +202,13 @@ {% endif %} {% endif %} + {% if c.slots_result %} + {{c.slots_result}} + {% elif c.casino_game_id %} + {% set game_state = c.casino_game.game_state_json %} + {{game_state['symbols'].replace(',','')}} {{game_state['text']}} + {% endif %} + {% if c.wordle_result %} {{c.wordle_html(v) | safe}} {% endif %}