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 03:33:44 +00:00
|
|
|
end_lottery_session(g)
|
|
|
|
return {"message": "Lottery ended."}
|
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):
|
|
|
|
start_new_lottery_session(g)
|
|
|
|
return {"message": "Lottery started."}
|
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):
|
|
|
|
most_recent_lottery = get_most_recent_lottery(g)
|
|
|
|
|
|
|
|
if most_recent_lottery is None or not most_recent_lottery.is_active:
|
|
|
|
return {"message": "There is no active lottery."}
|
|
|
|
|
|
|
|
return {"message": most_recent_lottery.stats}
|