rDrama/files/routes/lottery.py

48 lines
1.5 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.lottery import *
2022-05-29 00:02:35 +00:00
@app.post("/lottery/end")
@auth_required
def lottery_end(v):
if v.admin_level > 2:
success, message = end_lottery_session(g)
return {"message": message} if success else {"error": message}
else:
return {"error": "JL3+ or higher required to start and end lotteries."}, 401
2022-05-29 00:02:35 +00:00
@app.post("/lottery/start")
@auth_required
def lottery_start(v):
if v.admin_level > 2:
start_new_lottery_session(g)
return {"message": "Lottery started."}
else:
return {"error": "JL3+ or higher required to start and end lotteries."}, 401
2022-05-29 00:02:35 +00:00
@app.post("/lottery/buy")
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@auth_required
def lottery_buy(v):
2022-05-29 06:06:39 +00:00
success, message = purchase_lottery_ticket(g, v)
lottery, participants = get_active_lottery_stats(g)
2022-05-29 00:02:35 +00:00
if success:
2022-05-29 06:06:39 +00:00
return {"message": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}}
else:
2022-05-29 06:06:39 +00:00
return {"error": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}}
2022-05-29 00:02:35 +00:00
@app.get("/lottery/active")
2022-05-29 00:02:35 +00:00
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@auth_required
def lottery_active(v):
2022-05-29 06:01:45 +00:00
lottery, participants = get_active_lottery_stats(g)
return {"message": "", "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}}