33 lines
783 B
Python
33 lines
783 B
Python
|
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})
|