2022-05-28 23:26:30 +00:00
|
|
|
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 *
|
2022-05-29 03:33:44 +00:00
|
|
|
from files.helpers.lottery import *
|
2022-05-29 00:02:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.post("/lottery/end")
|
|
|
|
@auth_required
|
|
|
|
def lottery_end(v):
|
2022-05-29 04:23:20 +00:00
|
|
|
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
|
|
|
|
2022-05-29 03:33:44 +00:00
|
|
|
|
|
|
|
@app.post("/lottery/start")
|
|
|
|
@auth_required
|
|
|
|
def lottery_start(v):
|
2022-05-29 04:23:20 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2022-05-28 23:26:30 +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 03:33:44 +00:00
|
|
|
success, message, lottery_stats = purchase_lottery_ticket(g, v)
|
2022-05-29 00:02:35 +00:00
|
|
|
|
2022-05-29 03:33:44 +00:00
|
|
|
if success:
|
|
|
|
return {"message": message, "stats": {"user": v.lottery_stats, "lottery": lottery_stats}}
|
|
|
|
else:
|
|
|
|
return {"error": message, "stats": {"user": v.lottery_stats, "lottery": lottery_stats}}
|
2022-05-28 23:26:30 +00:00
|
|
|
|
2022-05-29 00:02:35 +00:00
|
|
|
|
2022-05-29 03:33:44 +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
|
2022-05-29 03:33:44 +00:00
|
|
|
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}}
|