This repository has been archived on 2024-05-20. You can view files and clone it, but cannot push or open issues or pull requests.
PriceyBot3/libs/http/users.py
2023-10-15 19:41:10 +11:00

32 lines
1.2 KiB
Python

import aiohttp
class UserRequests:
def __init__(self, API_URL, BOT_TOKEN):
self.API_URL = API_URL
self.headers = {"Content-Type": "application/json", "X-BOTAUTH": BOT_TOKEN}
async def getUser(self, user_id):
async with aiohttp.ClientSession(self.API_URL, headers=self.headers) as session:
# Make sure we have a good connection
async with session.head("/") as alive:
if alive.status != 200:
return None
async with session.get(f"/api/user/{user_id}") as data:
response = await data.json()
return response
async def registerUser(self, user_data: dict):
async with aiohttp.ClientSession(self.API_URL, headers=self.headers) as session:
# Make sure we have a good connection
async with session.head("/") as alive:
if alive.status != 200:
return None
async with session.post("/api/user/register", json=user_data) as data:
if data.status != 200:
return {"status": False}
response = await data.json()
return response