diff --git a/files/assets/images/chest.png b/files/assets/images/chest.png
new file mode 100644
index 000000000..3c5c87d51
Binary files /dev/null and b/files/assets/images/chest.png differ
diff --git a/files/classes/__init__.py b/files/classes/__init__.py
index f3335b7f9..11a5cc67a 100644
--- a/files/classes/__init__.py
+++ b/files/classes/__init__.py
@@ -11,6 +11,7 @@ from .votes import *
from .domains import *
from .slots import *
from .blackjack import *
+from .treasure import *
from .subscriptions import *
from files.__main__ import app
from .mod_logs import *
diff --git a/files/classes/blackjack.py b/files/classes/blackjack.py
index 7e98bef07..a03eecc6d 100644
--- a/files/classes/blackjack.py
+++ b/files/classes/blackjack.py
@@ -64,11 +64,9 @@ class Blackjack:
if self.command_word in in_text:
for word in in_text.split():
if self.command_word in word:
- try:
- wager = word[len(self.command_word):]
- wager_value = int(wager)
- except: break
-
+ wager = word[len(self.command_word):]
+ wager_value = int(wager)
+
if (wager_value < self.minimum_bet):
break
elif (wager_value > self.maximum_bet):
@@ -158,11 +156,12 @@ class Blackjack:
elif result == 'won':
reward = int(wager) * 2
elif result == 'blackjack':
- reward = floor(int(wager) * (3/2))
+ reward = int(wager) + floor(int(wager) * (3/2))
if (reward > 0):
user = from_comment.author
user.coins += reward
+ user.winnings += reward - int(wager)
self.db.add(user)
self.db.commit()
\ No newline at end of file
diff --git a/files/classes/comment.py b/files/classes/comment.py
index 756e774d1..3ecc16138 100644
--- a/files/classes/comment.py
+++ b/files/classes/comment.py
@@ -45,6 +45,7 @@ class Comment(Base):
ban_reason = Column(String)
slots_result = Column(String)
blackjack_result = Column(String)
+ treasure_amount = Column(String)
post = relationship("Submission", viewonly=True)
author = relationship("User", primaryjoin="User.id==Comment.author_id")
diff --git a/files/classes/treasure.py b/files/classes/treasure.py
new file mode 100644
index 000000000..5a5fedba2
--- /dev/null
+++ b/files/classes/treasure.py
@@ -0,0 +1,42 @@
+import random
+
+
+class Treasure:
+ special_min = 100
+ special_max = 1000
+ standard_min = 10
+ standard_max = 100
+
+ def __init__(self, g):
+ self.db = g.db
+
+ def check_for_treasure(self, in_text, from_comment):
+ has_gamble_command = '!slots' in in_text or '!blackjack' in in_text
+
+ if not has_gamble_command:
+ seed = random.randint(1, 1000)
+ is_special = seed == 1000 # 0.1% chance
+ is_standard = seed >= 990 # 1.0% chance
+ amount = 0
+
+ if is_special:
+ amount = random.randint(self.special_min, self.special_max)
+ elif is_standard:
+ amount = random.randint(self.standard_min, self.standard_max)
+
+ # Mimic: 25% chance
+ if random.randint(1, 100) > 75:
+ amount = -amount
+
+ if amount != 0:
+ user = from_comment.author
+ user.coins += amount
+
+ if user.coins < 0:
+ user.coins = 0
+
+ from_comment.treasure_amount = str(amount)
+
+ self.db.add(user)
+ self.db.add(from_comment)
+ self.db.commit()
diff --git a/files/routes/comments.py b/files/routes/comments.py
index 317671dbf..314dca141 100644
--- a/files/routes/comments.py
+++ b/files/routes/comments.py
@@ -595,6 +595,9 @@ def api_comment(v):
blackjack = Blackjack(g)
blackjack.check_for_blackjack_command(body, v, c)
+ treasure = Treasure(g)
+ treasure.check_for_treasure(body, c)
+
g.db.commit()
if request.headers.get("Authorization"): return c.json
diff --git a/files/templates/comments.html b/files/templates/comments.html
index 0f83ebc74..246d44add 100644
--- a/files/templates/comments.html
+++ b/files/templates/comments.html
@@ -181,6 +181,7 @@
{% set blackjack_status = split_result[3] %}
{% set player_hand = split_result[0].replace('X', '10') %}
{% set dealer_hand = split_result[1].split('/')[0] if blackjack_status == 'active' else split_result[1] %}
+ {% set dealer_hand = dealer_hand.replace('X', '10') %}
{% set wager = split_result[4] %}
{% endif %}
@@ -238,6 +239,15 @@
· Edited {{c.edited_string}}
{% endif %}
+ {% if c.treasure_amount and c.treasure_amount != '0' %}
+
+ {% if '-' in c.treasure_amount %}
+ A Mimic Ate {{c.treasure_amount.replace('-', '')}} Coins!
+ {% else %}
+ Found {{c.treasure_amount}} Coins!
+ {% endif %}
+ {% endif %}
+
{% if c.slots_result %}
{{c.slots_result}}
{% endif %}
diff --git a/schema.sql b/schema.sql
index 05f96005e..f84fe3493 100644
--- a/schema.sql
+++ b/schema.sql
@@ -301,7 +301,8 @@ CREATE TABLE public.comments (
is_pinned_utc integer,
ghost boolean,
slots_result character varying(50),
- blackjack_result character varying(3000)
+ blackjack_result character varying(3000),
+ treasure_amount character varying(10)
);