2022-11-15 09:19:08 +00:00
|
|
|
import time
|
|
|
|
from files.classes.casino_game import Casino_Game
|
2022-09-10 21:01:34 +00:00
|
|
|
from files.helpers.alerts import *
|
|
|
|
from files.helpers.const import *
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.helpers.useractions import badge_grant
|
2022-09-27 10:56:57 +00:00
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
def get_game_feed(game, db):
|
|
|
|
games = db.query(Casino_Game) \
|
2022-10-28 23:39:31 +00:00
|
|
|
.filter(Casino_Game.active == False, Casino_Game.kind == game) \
|
|
|
|
.order_by(Casino_Game.created_utc.desc()).limit(30).all()
|
2022-09-10 21:01:34 +00:00
|
|
|
|
2022-10-28 23:39:31 +00:00
|
|
|
def format_game(game):
|
2022-11-15 09:19:08 +00:00
|
|
|
user = db.query(User).filter(User.id == game.user_id).one()
|
2022-10-28 23:39:31 +00:00
|
|
|
wonlost = 'lost' if game.winnings < 0 else 'won'
|
|
|
|
relevant_currency = "coin" if game.currency == "coins" else "marseybux"
|
2022-09-10 21:01:34 +00:00
|
|
|
|
2022-10-28 23:39:31 +00:00
|
|
|
return {
|
|
|
|
"user": user.username,
|
|
|
|
"won_or_lost": wonlost,
|
|
|
|
"amount": abs(game.winnings),
|
|
|
|
"currency": relevant_currency
|
|
|
|
}
|
2022-09-10 21:01:34 +00:00
|
|
|
|
2022-10-28 23:39:31 +00:00
|
|
|
return list(map(format_game, games))
|
2022-09-10 21:01:34 +00:00
|
|
|
|
2022-11-22 15:11:01 +00:00
|
|
|
def get_user_stats(u:User, game:str, db:scoped_session, include_ties=False):
|
|
|
|
games = db.query(Casino_Game.user_id, Casino_Game.winnings).filter(Casino_Game.kind == game, Casino_Game.user_id == u.id)
|
|
|
|
wins = games.filter(Casino_Game.winnings > 0).count()
|
|
|
|
ties = games.filter(Casino_Game.winnings == 0).count() if include_ties else 0
|
|
|
|
losses = games.filter(Casino_Game.winnings < 0).count()
|
|
|
|
return (wins, ties, losses)
|
|
|
|
|
|
|
|
def get_game_leaderboard(game, db:scoped_session):
|
2022-10-28 23:39:31 +00:00
|
|
|
timestamp_24h_ago = time.time() - 86400
|
2022-11-15 09:19:08 +00:00
|
|
|
timestamp_all_time = CASINO_RELEASE_DAY # "All Time" starts on release day
|
2022-09-10 21:06:47 +00:00
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
biggest_win_all_time = db.query(Casino_Game.user_id, User.username, Casino_Game.currency, Casino_Game.winnings).select_from(
|
2022-10-28 23:39:31 +00:00
|
|
|
Casino_Game).join(User).order_by(Casino_Game.winnings.desc()).filter(Casino_Game.kind == game, Casino_Game.created_utc > timestamp_all_time).limit(1).one_or_none()
|
2022-09-10 21:01:34 +00:00
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
biggest_win_last_24h = db.query(Casino_Game.user_id, User.username, Casino_Game.currency, Casino_Game.winnings).select_from(
|
2022-10-28 23:39:31 +00:00
|
|
|
Casino_Game).join(User).order_by(Casino_Game.winnings.desc()).filter(Casino_Game.kind == game, Casino_Game.created_utc > timestamp_24h_ago).limit(1).one_or_none()
|
2022-09-10 21:01:34 +00:00
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
biggest_loss_all_time = db.query(Casino_Game.user_id, User.username, Casino_Game.currency, Casino_Game.winnings).select_from(
|
2022-10-28 23:39:31 +00:00
|
|
|
Casino_Game).join(User).order_by(Casino_Game.winnings.asc()).filter(Casino_Game.kind == game, Casino_Game.created_utc > timestamp_all_time).limit(1).one_or_none()
|
2022-09-10 21:01:34 +00:00
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
biggest_loss_last_24h = db.query(Casino_Game.user_id, User.username, Casino_Game.currency, Casino_Game.winnings).select_from(
|
2022-10-28 23:39:31 +00:00
|
|
|
Casino_Game).join(User).order_by(Casino_Game.winnings.asc()).filter(Casino_Game.kind == game, Casino_Game.created_utc > timestamp_24h_ago).limit(1).one_or_none()
|
2022-09-10 21:01:34 +00:00
|
|
|
|
2022-10-28 23:39:31 +00:00
|
|
|
if not biggest_win_all_time:
|
|
|
|
biggest_win_all_time = [None, None, None, 0]
|
2022-09-10 21:01:34 +00:00
|
|
|
|
2022-10-28 23:39:31 +00:00
|
|
|
if not biggest_win_last_24h:
|
|
|
|
biggest_win_last_24h = [None, None, None, 0]
|
2022-09-10 21:01:34 +00:00
|
|
|
|
2022-10-28 23:39:31 +00:00
|
|
|
if not biggest_loss_all_time:
|
|
|
|
biggest_loss_all_time = [None, None, None, 0]
|
2022-09-10 21:01:34 +00:00
|
|
|
|
2022-10-28 23:39:31 +00:00
|
|
|
if not biggest_loss_last_24h:
|
|
|
|
biggest_loss_last_24h = [None, None, None, 0]
|
2022-09-10 21:01:34 +00:00
|
|
|
|
|
|
|
|
2022-10-28 23:39:31 +00:00
|
|
|
return {
|
|
|
|
"all_time": {
|
|
|
|
"biggest_win": {
|
2022-09-10 21:01:34 +00:00
|
|
|
"user": biggest_win_all_time[1],
|
|
|
|
"currency": biggest_win_all_time[2],
|
|
|
|
"amount": biggest_win_all_time[3]
|
|
|
|
},
|
2022-10-28 23:39:31 +00:00
|
|
|
"biggest_loss": {
|
2022-09-10 21:01:34 +00:00
|
|
|
"user": biggest_loss_all_time[1],
|
|
|
|
"currency": biggest_loss_all_time[2],
|
|
|
|
"amount": abs(biggest_loss_all_time[3])
|
|
|
|
}
|
2022-10-28 23:39:31 +00:00
|
|
|
},
|
|
|
|
"last_24h": {
|
|
|
|
"biggest_win": {
|
2022-09-10 21:01:34 +00:00
|
|
|
"user": biggest_win_last_24h[1],
|
|
|
|
"currency": biggest_win_last_24h[2],
|
|
|
|
"amount": biggest_win_last_24h[3]
|
|
|
|
},
|
2022-10-28 23:39:31 +00:00
|
|
|
"biggest_loss": {
|
2022-09-10 21:01:34 +00:00
|
|
|
"user": biggest_loss_last_24h[1],
|
|
|
|
"currency": biggest_loss_last_24h[2],
|
|
|
|
"amount": abs(biggest_loss_last_24h[3])
|
|
|
|
}
|
2022-10-28 23:39:31 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-29 04:26:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
def distribute_wager_badges(user, wager, won):
|
2022-10-28 23:39:31 +00:00
|
|
|
badges_earned = []
|
|
|
|
|
|
|
|
if won:
|
|
|
|
if wager >= 1000:
|
|
|
|
badges_earned.append(160)
|
|
|
|
if wager >= 10000:
|
|
|
|
badges_earned.append(161)
|
|
|
|
if wager >= 100000:
|
|
|
|
badges_earned.append(162)
|
|
|
|
else:
|
|
|
|
if wager >= 1000:
|
|
|
|
badges_earned.append(157)
|
|
|
|
if wager >= 10000:
|
|
|
|
badges_earned.append(158)
|
|
|
|
if wager >= 100000:
|
|
|
|
badges_earned.append(159)
|
|
|
|
|
|
|
|
for badge in badges_earned:
|
|
|
|
badge_grant(user, badge)
|