create user database
This commit is contained in:
parent
fed2849f0f
commit
3193ca6b56
28
driver/database/dbusers.py
Normal file
28
driver/database/dbusers.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
from typing import Dict, List, Union
|
||||||
|
from driver.database.dblocal import db
|
||||||
|
|
||||||
|
usersdb = db.users
|
||||||
|
|
||||||
|
|
||||||
|
async def is_served_user(user_id: int) -> bool:
|
||||||
|
user = await usersdb.find_one({"user_id": user_id})
|
||||||
|
if not user:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
async def get_served_users() -> list:
|
||||||
|
users = usersdb.find({"user_id": {"$gt": 0}})
|
||||||
|
if not users:
|
||||||
|
return []
|
||||||
|
users_list = []
|
||||||
|
for user in await users.to_list(length=1000000000):
|
||||||
|
users_list.append(user)
|
||||||
|
return users_list
|
||||||
|
|
||||||
|
|
||||||
|
async def add_served_user(user_id: int):
|
||||||
|
is_served = await is_served_user(user_id)
|
||||||
|
if is_served:
|
||||||
|
return
|
||||||
|
return await usersdb.insert_one({"user_id": user_id})
|
Loading…
Reference in New Issue
Block a user