forked from rDrama/rDrama
slots: fix numerous bugs with slots
slots: fix missing imports (x2) slots: fix other user errors being returned to a potentially completely unrelated user for example if Snappy was under the rehab effect and it pulled the slot, it'd abort and potentially cause other bugs down the chain, which makes no sense to a user or could leave a post in a wonky statemaster
parent
c013463047
commit
cd33fa9046
|
@ -4,6 +4,7 @@ from files.helpers.alerts import send_repeatable_notification
|
|||
from files.helpers.const import *
|
||||
from files.helpers.get import *
|
||||
from files.helpers.sanitize import *
|
||||
from files.helpers.slots import execute_slots_command
|
||||
import random
|
||||
from urllib.parse import quote
|
||||
|
||||
|
@ -171,8 +172,7 @@ def execute_snappy(post, v):
|
|||
snappy.coins += 1
|
||||
g.db.add(snappy)
|
||||
|
||||
if c.body.startswith('!slots'):
|
||||
execute_slots_command(snappy, c)
|
||||
execute_slots_command(snappy, v, c)
|
||||
|
||||
if FEATURES['PINS'] and (body.startswith(':#marseypin:') or body.startswith(':#marseypin2:')):
|
||||
post.stickied = "Snappy"
|
||||
|
|
|
@ -4,7 +4,9 @@ import random
|
|||
from .const import *
|
||||
from files.classes.casino_game import Casino_Game
|
||||
from files.helpers.casino import distribute_wager_badges
|
||||
from flask import g
|
||||
from flask import g, abort
|
||||
from files.classes.comment import Comment
|
||||
from files.classes.user import User
|
||||
|
||||
minimum_bet = 5
|
||||
maximum_bet = INFINITY
|
||||
|
@ -115,32 +117,42 @@ def shuffle(stuff):
|
|||
return stuff
|
||||
|
||||
|
||||
def execute_slots_command(u, c):
|
||||
def execute_slots_command(v:User, u:User, c:Comment):
|
||||
if not FEATURES['GAMBLING']: return
|
||||
body = c.body.lower()
|
||||
|
||||
if u.rehab:
|
||||
abort(403, "You are under Rehab award effect!")
|
||||
|
||||
if '!slotsmb' in body:
|
||||
command_word = '!slotsmb'
|
||||
currency = 'procoins'
|
||||
else:
|
||||
elif '!slots' in body:
|
||||
command_word = '!slots'
|
||||
currency = 'coins'
|
||||
else:
|
||||
return
|
||||
|
||||
if u.rehab:
|
||||
if v.id == u.id:
|
||||
abort(403, "You are under Rehab award effect!")
|
||||
return
|
||||
|
||||
wager = body.split(command_word)[1].split()[0]
|
||||
|
||||
try:
|
||||
wager = int(wager)
|
||||
except:
|
||||
abort(400, "Invalid wager.")
|
||||
if v.id == u.id:
|
||||
abort(400, "Invalid wager.")
|
||||
return
|
||||
|
||||
if wager < 100:
|
||||
abort(400, f"Wager must be 100 {currency} or more")
|
||||
if v.id == u.id:
|
||||
abort(400, f"Wager must be 100 {currency} or more")
|
||||
return
|
||||
|
||||
if (currency == "coins" and wager > u.coins) or (currency == "procoins" and wager > u.procoins):
|
||||
abort(400, f"Not enough {currency} to make that bet")
|
||||
if v.id == u.id:
|
||||
abort(400, f"Not enough {currency} to make that bet")
|
||||
return
|
||||
|
||||
game_id, game_state = casino_slot_pull(v, wager, currency)
|
||||
|
||||
c.casino_game_id = game_id
|
||||
|
|
|
@ -357,8 +357,7 @@ def comment(v):
|
|||
parent_post.comment_count += 1
|
||||
g.db.add(parent_post)
|
||||
|
||||
if FEATURES['GAMBLING'] and '!slots' in c.body.lower():
|
||||
execute_slots_command(v, c)
|
||||
execute_slots_command(v, v, c)
|
||||
|
||||
g.db.flush()
|
||||
|
||||
|
|
Loading…
Reference in New Issue