rDrama/files/routes/lottery.py

59 lines
1.9 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.wrappers import *
from files.helpers.lottery import *
import requests
2022-05-29 00:02:35 +00:00
@app.post("/lottery/end")
2022-10-11 13:19:55 +00:00
@feature_required('GAMBLING')
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
@app.post("/lottery/start")
2022-10-11 13:19:55 +00:00
@feature_required('GAMBLING')
2022-11-14 15:11:05 +00:00
@admin_level_required(PERMS['LOTTERY_ADMIN'])
def lottery_start(v):
2022-06-13 18:33:25 +00:00
start_new_lottery_session()
return {"message": "Lottery started."}
2022-05-29 00:02:35 +00:00
@app.post("/lottery/buy")
2022-11-14 15:11:05 +00:00
@feature_required('GAMBLING')
@limiter.limit("3/second;100/minute;500/hour;1000/day")
@auth_required
def lottery_buy(v):
try: quantity = int(request.values.get("quantity"))
except: abort(400, "Invalid ticket quantity.")
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-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-29 00:02:35 +00:00
@app.get("/lottery/active")
2022-11-14 15:11:05 +00:00
@feature_required('GAMBLING')
@limiter.limit("3/second;100/minute;500/hour;1000/day")
2022-05-29 00:02:35 +00:00
@auth_required
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
@app.get("/admin/lottery/participants")
2022-10-11 13:19:55 +00:00
@feature_required('GAMBLING')
2022-11-14 15:11:05 +00:00
@admin_level_required(PERMS['LOTTERY_VIEW_PARTICIPANTS'])
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)