Added redis cache and user registration system

This commit is contained in:
benjamyn committed 2023-10-15 18:54:25 +11:00
1 parent 391687bc15
commit 4efb02784c
6 files changed
+135 -8

No files matched your search

+1
View File
@@ -0,0 +1 @@
from . import users
+31
View File
@@ -0,0 +1,31 @@
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 False
response = await data.json()
return response