32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
|
from fastapi import FastAPI, HTTPException
|
||
|
from db import MySQLDB
|
||
|
from PlayerSubscription import PlayerSubscription
|
||
|
|
||
|
app = FastAPI()
|
||
|
db = MySQLDB()
|
||
|
|
||
|
@app.post("/subscribe")
|
||
|
async def subscribe(player_data: PlayerSubscription):
|
||
|
await db.connect()
|
||
|
try:
|
||
|
|
||
|
uuid_query = "SELECT uuid FROM luckperms_players WHERE username = %s"
|
||
|
result = await db.execute(uuid_query, player_data.username)
|
||
|
if not result:
|
||
|
raise HTTPException(status_code=404, detail="Player not found")
|
||
|
uuid = result[0][0]
|
||
|
|
||
|
subscription_query = """
|
||
|
INSERT INTO luckperms_user_permissions (uuid, permission, value, server, world, expiry, contexts)
|
||
|
VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||
|
"""
|
||
|
await db.execute(subscription_query, uuid, 'group.subscribe', 1, 'global', 'global', player_data.expiry, "{}")
|
||
|
finally:
|
||
|
await db.close()
|
||
|
|
||
|
return {"message": "Subscription added successfully"}
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
import uvicorn
|
||
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|