video-stream/driver/database/dblockchat.py
levina de9f835cfe
setup database
create new database for blacklist chat and whitelist chat
2022-02-07 18:47:41 +07:00

27 lines
738 B
Python

from typing import Dict, List, Union
from driver.database.dblocal import db
blacklist_chatdb = db.blacklistChat
async def blacklisted_chats() -> list:
chats = blacklist_chatdb.find({"chat_id": {"$lt": 0}})
return [
chat["chat_id"] for chat in await chats.to_list(length=1000000000)
]
async def blacklist_chat(chat_id: int) -> bool:
if not await blacklist_chatdb.find_one({"chat_id": chat_id}):
await blacklist_chatdb.insert_one({"chat_id": chat_id})
return True
return False
async def whitelist_chat(chat_id: int) -> bool:
if await blacklist_chatdb.find_one({"chat_id": chat_id}):
await blacklist_chatdb.delete_one({"chat_id": chat_id})
return True
return False