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
|
|
|
|
2022-05-29 03:33:44 +00:00
|
|
|
@app.post("/lottery/start")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, 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")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit("100/minute;500/hour;1000/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("100/minute;500/hour;1000/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-05-28 23:26:30 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def lottery_buy(v):
|
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")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit("100/minute;500/hour;1000/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("100/minute;500/hour;1000/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-05-29 00:02:35 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
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
|
|
|
|
2022-06-01 03:20:39 +00:00
|
|
|
@app.get("/admin/lottery/participants")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, 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)
|