Compare commits

..

No commits in common. "1e772e7034835ee946de889d602bfd75e083009f" and "29b15f07b7d7b7a31ec7a50a964adaa816e87dba" have entirely different histories.

5 changed files with 0 additions and 89 deletions

1
.gitignore vendored
View File

@ -160,4 +160,3 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
config.yml

View File

@ -1,13 +0,0 @@
from pydantic import BaseModel, field_validator
from typing import Optional
class PlayerSubscription(BaseModel):
username: str
expiry: Optional[int] = None
@field_validator('expiry')
@classmethod
def expiry_must_be_positive_int(cls, v):
if v is not None and not isinstance(v, int) or v < 0:
raise ValueError('Expiry must be a positive integer')
return v

27
db.py
View File

@ -1,27 +0,0 @@
import aiomysql
from utils import get_parameters
class MySQLDB:
def __init__(self):
self.pool = None
self.parameters = get_parameters()
print(self.parameters)
async def connect(self):
self.pool = await aiomysql.create_pool(
host=self.parameters["host"],
port=self.parameters["port"],
user=self.parameters["user"],
password=self.parameters["password"],
db=self.parameters["db"],
autocommit=True
)
async def close(self):
self.pool.close()
await self.pool.wait_closed()
async def execute(self, query, *args):
async with self.pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute(query, args)
return await cur.fetchall()

31
main.py
View File

@ -1,31 +0,0 @@
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)

View File

@ -1,17 +0,0 @@
import yaml
def read_config(config_file):
with open(config_file, 'r') as file:
config = yaml.safe_load(file)
return config
def get_parameters():
parameters = {}
config = read_config('config.yml')
for key, value in config.items():
if isinstance(value, dict):
for sub_key, sub_value in value.items():
parameters[f'{key}_{sub_key}'] = sub_value
else:
parameters[key] = value
return parameters