video-stream/driver/database/dbpunish.py

33 lines
783 B
Python
Raw Permalink Normal View History

2022-01-31 12:01:11 +00:00
from typing import Dict, List, Union
from driver.database.dblocal import db
gbansdb = db.gban
async def get_gbans_count() -> int:
users = gbansdb.find({"user_id": {"$gt": 0}})
users = await users.to_list(length=100000)
return len(users)
async def is_gbanned_user(user_id: int) -> bool:
user = await gbansdb.find_one({"user_id": user_id})
if not user:
return False
return True
async def add_gban_user(user_id: int):
is_gbanned = await is_gbanned_user(user_id)
if is_gbanned:
return
return await gbansdb.insert_one({"user_id": user_id})
async def remove_gban_user(user_id: int):
is_gbanned = await is_gbanned_user(user_id)
if not is_gbanned:
return
return await gbansdb.delete_one({"user_id": user_id})