2022-05-28 23:26:30 +00:00
|
|
|
from files.helpers.alerts import *
|
2022-12-11 23:44:34 +00:00
|
|
|
from files.helpers.config.const import *
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.helpers.get import *
|
2022-05-29 03:33:44 +00:00
|
|
|
from files.helpers.lottery import *
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.routes.wrappers import *
|
|
|
|
|
|
|
|
from files.__main__ import app, limiter
|
2022-05-29 00:02:35 +00:00
|
|
|
|
|
|
|
@app.post("/lottery/end")
|
2023-01-21 04:39:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
2022-11-14 15:11:05 +00:00
|
|
|
@admin_level_required(PERMS['LOTTERY_ADMIN'])
|
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
|
|
|
|
2022-05-29 03:33:44 +00:00
|
|
|
|
|
|
|
@app.post("/lottery/start")
|
2023-01-21 04:39:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
2022-11-14 15:11:05 +00:00
|
|
|
@admin_level_required(PERMS['LOTTERY_ADMIN'])
|
2022-05-29 03:33:44 +00:00
|
|
|
def lottery_start(v):
|
2022-06-13 18:33:25 +00:00
|
|
|
start_new_lottery_session()
|
2023-01-27 11:57:29 +00:00
|
|
|
return {"message": "Lottery started!"}
|
2022-05-29 00:02:35 +00:00
|
|
|
|
|
|
|
|
2022-05-28 23:26:30 +00:00
|
|
|
@app.post("/lottery/buy")
|
2022-05-30 04:31:48 +00:00
|
|
|
@limiter.limit("3/second;100/minute;500/hour;1000/day")
|
2023-01-21 04:39:46 +00:00
|
|
|
@limiter.limit("3/second;100/minute;500/hour;1000/day", key_func=get_ID)
|
2022-05-28 23:26:30 +00:00
|
|
|
@auth_required
|
2022-11-26 21:00:03 +00:00
|
|
|
def lottery_buy(v:User):
|
2022-06-13 18:34:57 +00:00
|
|
|
try: quantity = int(request.values.get("quantity"))
|
2023-01-27 11:57:29 +00:00
|
|
|
except: abort(400, "Invalid ticket quantity!")
|
2022-06-13 18:34:57 +00:00
|
|
|
|
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-02 23:19:49 +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-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-30 04:31:48 +00:00
|
|
|
@limiter.limit("3/second;100/minute;500/hour;1000/day")
|
2023-01-21 04:39:46 +00:00
|
|
|
@limiter.limit("3/second;100/minute;500/hour;1000/day", key_func=get_ID)
|
2022-05-29 00:02:35 +00:00
|
|
|
@auth_required
|
2022-11-26 21:00:03 +00:00
|
|
|
def lottery_active(v:User):
|
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
|
|
|
|
2022-06-01 03:20:39 +00:00
|
|
|
@app.get("/admin/lottery/participants")
|
2023-01-21 04:39:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
2022-11-14 15:11:05 +00:00
|
|
|
@admin_level_required(PERMS['LOTTERY_VIEW_PARTICIPANTS'])
|
2022-06-01 03:20:39 +00:00
|
|
|
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)
|