Archived
Added redis cache and user registration system
This commit is contained in:
1 parent
391687bc15
commit
4efb02784c
6 files changed
+135
-8
No files matched your search
@@ -0,0 +1 @@
|
||||
from . import users
|
||||
@@ -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
|
||||
Reference in new issue
Block a user