Slots (#175)
* Initial commit. * Changes * Remove dead code * Remove dead code * Remove dead code Co-authored-by: Outrun Colors, LLC <outruncolors@gmail.com> Co-authored-by: Aevann1 <59999695+Aevann1@users.noreply.github.com>remotes/1693045480750635534/spooky-22
parent
b4ec1e6150
commit
cdd8c930a8
|
@ -10,4 +10,6 @@ under_attack
|
|||
venv/
|
||||
.vscode/
|
||||
.sass-cache/
|
||||
flask_session/
|
||||
flask_session/
|
||||
marsey_count.json
|
||||
.DS_Store
|
|
@ -9,6 +9,7 @@ from .userblock import *
|
|||
from .submission import *
|
||||
from .votes import *
|
||||
from .domains import *
|
||||
from .slots import *
|
||||
from .subscriptions import *
|
||||
from files.__main__ import app
|
||||
from .mod_logs import *
|
||||
|
|
|
@ -43,6 +43,7 @@ class Comment(Base):
|
|||
body = Column(String)
|
||||
body_html = Column(String)
|
||||
ban_reason = Column(String)
|
||||
slots_result = Column(String, default="")
|
||||
|
||||
post = relationship("Submission", viewonly=True)
|
||||
author = relationship("User", primaryjoin="User.id==Comment.author_id")
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
from json.encoder import INFINITY
|
||||
import random
|
||||
from .comment import *
|
||||
from files.helpers.const import *
|
||||
|
||||
class Slots:
|
||||
commandWord = "!slots"
|
||||
minimumBet = 5
|
||||
maximumBet = INFINITY
|
||||
symbols = {"♦️", "♠️", "♥️", "♣️", "⚧", "🔞", "⚛️", "☢️", "✡️", "⚔️", "🐱"}
|
||||
|
||||
# Common...
|
||||
commonRatio = 4
|
||||
commonPayout = 2
|
||||
|
||||
# Uncommon.
|
||||
uncommonIndex = 4
|
||||
uncommonRatio = 3
|
||||
uncommonPayout = 3
|
||||
|
||||
# Rare~
|
||||
rareIndex = 8
|
||||
rareRatio = 2
|
||||
rarePayout = 5
|
||||
|
||||
# Jackpot!
|
||||
jackpotIndex = 10
|
||||
jackpotRatio = 1
|
||||
jackpotPayout = 100
|
||||
|
||||
def __init__(self, g):
|
||||
self.db = g.db
|
||||
|
||||
# Check for !slots<wager>
|
||||
def check_for_slots_command(self, in_text, from_user, from_comment):
|
||||
if self.commandWord in in_text:
|
||||
for word in in_text.split():
|
||||
if self.commandWord in word:
|
||||
try:
|
||||
wager = word[len(self.commandWord):]
|
||||
wagerValue = int(wager, base=10)
|
||||
|
||||
if self.wager_is_valid(from_user, wagerValue):
|
||||
result = self.pull_the_arm(from_user, wagerValue, from_comment)
|
||||
return { 'pulled': True, 'result': result }
|
||||
|
||||
except ValueError:
|
||||
break
|
||||
return { 'pulled': False, 'result': '' }
|
||||
|
||||
# Ensure user is capable of the wager
|
||||
def wager_is_valid(self, from_user, wager):
|
||||
if (wager < self.minimumBet):
|
||||
return False
|
||||
elif (wager > self.maximumBet):
|
||||
return False
|
||||
elif (wager > from_user.coins):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
# Generate full set of symbols.
|
||||
def count_out_symbols(self):
|
||||
countedSymbols = []
|
||||
payoutLookup = {}
|
||||
index = 0
|
||||
|
||||
for item in self.symbols:
|
||||
count = 0
|
||||
|
||||
if index == self.jackpotIndex:
|
||||
count = self.jackpotRatio
|
||||
payoutLookup[item] = self.jackpotPayout
|
||||
elif index >= self.rareIndex:
|
||||
count = self.rareRatio
|
||||
payoutLookup[item] = self.rarePayout
|
||||
elif index >= self.uncommonIndex:
|
||||
count = self.uncommonRatio
|
||||
payoutLookup[item] = self.uncommonPayout
|
||||
else:
|
||||
count = self.commonRatio
|
||||
payoutLookup[item] = self.commonPayout
|
||||
|
||||
while count > 0:
|
||||
countedSymbols.append(item)
|
||||
count -= 1
|
||||
|
||||
index += 1
|
||||
|
||||
random.shuffle(countedSymbols)
|
||||
|
||||
return { 'symbols': countedSymbols, 'payout': payoutLookup }
|
||||
|
||||
# Consolation prizes return the user's wager.
|
||||
def check_for_consolation(self, symbols):
|
||||
# 1. Any 2 matching.
|
||||
if symbols[0] == symbols[1] or symbols[0] == symbols[2] or symbols[1] == symbols[2]:
|
||||
return True
|
||||
# 2. Any instance of jackpot.
|
||||
for symbol in symbols:
|
||||
if symbol == "🐱":
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
# Actually make the relevant calls
|
||||
def pull_the_arm(self, from_user, amount, from_comment):
|
||||
# Charge user for the bet
|
||||
self.charge_user(from_user, amount)
|
||||
|
||||
# Determine the outcome
|
||||
result1 = self.count_out_symbols()
|
||||
result2 = self.count_out_symbols()
|
||||
result3 = self.count_out_symbols()
|
||||
symbol1 = result1['symbols'][0]
|
||||
symbol2 = result2['symbols'][0]
|
||||
symbol3 = result3['symbols'][0]
|
||||
payout = result1['payout'][symbol1]
|
||||
isMatch = symbol1 == symbol2 and symbol2 == symbol3
|
||||
resultSymbols = [symbol1, symbol2, symbol3]
|
||||
isConsolation = self.check_for_consolation(resultSymbols)
|
||||
|
||||
if isMatch:
|
||||
# Pay out
|
||||
reward = amount * payout
|
||||
self.credit_user(from_user, reward)
|
||||
elif isConsolation:
|
||||
# Refund wager
|
||||
self.credit_user(from_user, amount)
|
||||
|
||||
return "".join(resultSymbols)
|
||||
|
||||
# Credit the user's account
|
||||
def credit_user(self, from_user, amount):
|
||||
from_user.coins += amount
|
||||
|
||||
self.db.add(from_user)
|
||||
self.db.commit()
|
||||
|
||||
# Charge the user's account
|
||||
def charge_user(self, from_user, amount):
|
||||
from_user.coins -= amount
|
||||
|
||||
self.db.add(from_user)
|
||||
self.db.commit()
|
|
@ -123,7 +123,6 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
|||
else: template = "submission.html"
|
||||
return render_template(template, v=v, p=post, sort=sort, comment_info=comment_info, render_replies=True)
|
||||
|
||||
|
||||
@app.post("/comment")
|
||||
@limiter.limit("1/second;6/minute;200/hour;1000/day")
|
||||
@auth_required
|
||||
|
@ -561,6 +560,15 @@ def api_comment(v):
|
|||
|
||||
g.db.commit()
|
||||
|
||||
# Slots
|
||||
slots = Slots(g)
|
||||
slots_check = slots.check_for_slots_command(body, v, c)
|
||||
|
||||
if (slots_check['pulled'] == True):
|
||||
c.slots_result = slots_check['result']
|
||||
g.db.add(c)
|
||||
g.db.commit()
|
||||
|
||||
if request.headers.get("Authorization"): return c.json
|
||||
return render_template("comments.html", v=v, comments=[c])
|
||||
|
||||
|
|
|
@ -86,8 +86,6 @@
|
|||
{% if (c.is_banned or c.deleted_utc or c.is_blocking) and not (v and v.admin_level > 1) and not (v and v.id==c.author_id) %}
|
||||
|
||||
<div id="comment-{{c.id}}" class="comment">
|
||||
|
||||
|
||||
<span class="comment-collapse-desktop d-none d-md-block" style="border-left: 2px solid #{{c.author.namecolor}};" onclick="collapse_comment('{{c.id}}')"></span>
|
||||
|
||||
<div class="comment-body">
|
||||
|
@ -231,6 +229,10 @@
|
|||
{% if c.edited_utc %}
|
||||
<span class="time-edited" id="time-edit-{{c.id}}" onmouseover="timestamp('time-edit-{{c.id}}','{{c.edited_utc}}')"><span>·</span> <span class="font-italic">Edited {{c.edited_string}}</span></span>
|
||||
{% endif %}
|
||||
|
||||
{% if c.slots_result %}
|
||||
<span style="position: relative; top: 2px; margin-left: 0.5rem">{{c.slots_result}}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if c.active_flags %}
|
||||
<div id="flaggers-{{c.id}}" class="flaggers d-none">
|
||||
|
|
|
@ -264,6 +264,7 @@ CREATE TABLE public.comments (
|
|||
body character varying(10000),
|
||||
body_html character varying(40000),
|
||||
ban_reason character varying(25),
|
||||
slots_result character varying(30),
|
||||
realupvotes integer,
|
||||
top_comment_id integer,
|
||||
is_pinned_utc integer,
|
||||
|
|
Loading…
Reference in New Issue