MarseyWorld/files/routes/lottery.py

59 lines
1.8 KiB
Python
Raw Normal View History

from files.__main__ import app, limiter
from files.helpers.wrappers import *
from files.helpers.alerts import *
from files.helpers.get import *
from files.helpers.const import *
from files.helpers.wrappers import *
from files.helpers.lottery import *
import requests
2022-05-29 00:02:35 +00:00
@app.post("/lottery/end")
2022-10-06 03:09:20 +00:00
@admin_level_required(PERMS['LOTTERY_ADMIN'])
2022-09-04 21:35:18 +00:00
@casino_required
2022-05-29 00:02:35 +00:00
def lottery_end(v):
2022-06-13 18:33:25 +00:00
success, message = end_lottery_session()
return {"message": message} if success else {"error": message}
2022-05-29 00:02:35 +00:00
@app.post("/lottery/start")
2022-10-06 03:09:20 +00:00
@admin_level_required(PERMS['LOTTERY_ADMIN'])
2022-09-04 21:35:18 +00:00
@casino_required
def lottery_start(v):
2022-06-13 18:33:25 +00:00
start_new_lottery_session()
return {"message": "Lottery started."}
2022-05-29 00:02:35 +00:00
@app.post("/lottery/buy")
@limiter.limit("3/second;100/minute;500/hour;1000/day")
@auth_required
2022-09-04 21:35:18 +00:00
@casino_required
def lottery_buy(v):
try: quantity = int(request.values.get("quantity"))
2022-09-12 09:52:07 +00:00
except: return {"error": "Invalid ticket quantity."}, 400
2022-06-13 18:33:25 +00:00
success, message = purchase_lottery_tickets(v, quantity)
lottery, participants = get_active_lottery_stats()
2022-05-29 00:02:35 +00:00
2022-06-13 18:33:25 +00:00
if success:
return {"message": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}}
else:
return {"error": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}}
2022-05-29 00:02:35 +00:00
@app.get("/lottery/active")
@limiter.limit("3/second;100/minute;500/hour;1000/day")
2022-05-29 00:02:35 +00:00
@auth_required
2022-09-04 21:35:18 +00:00
@casino_required
def lottery_active(v):
2022-06-13 18:33:25 +00:00
lottery, participants = get_active_lottery_stats()
2022-05-30 00:49:14 +00:00
2022-06-13 18:33:25 +00:00
return {"message": "", "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}}
2022-05-31 02:40:38 +00:00
@app.get("/admin/lottery/participants")
2022-10-06 03:09:20 +00:00
@admin_level_required(PERMS['LOTTERY_VIEW_PARTICIPANTS'])
2022-09-04 21:35:18 +00:00
@casino_required
def lottery_admin(v):
2022-06-13 18:33:25 +00:00
participants = get_users_participating_in_lottery()
return render_template("admin/lottery.html", v=v, participants=participants)