create database
This commit is contained in:
parent
55c952ab11
commit
5c68699e2c
38
driver/database/dbchat.py
Normal file
38
driver/database/dbchat.py
Normal file
@ -0,0 +1,38 @@
|
||||
""" chat database """
|
||||
|
||||
from typing import Dict, List, Union
|
||||
|
||||
from driver.database.dblocal import db
|
||||
|
||||
chatsdb = db.chats
|
||||
|
||||
|
||||
async def get_served_chats() -> list:
|
||||
chats = chatsdb.find({"chat_id": {"$lt": 0}})
|
||||
if not chats:
|
||||
return []
|
||||
chats_list = []
|
||||
for chat in await chats.to_list(length=1000000000):
|
||||
chats_list.append(chat)
|
||||
return chats_list
|
||||
|
||||
|
||||
async def is_served_chat(chat_id: int) -> bool:
|
||||
chat = await chatsdb.find_one({"chat_id": chat_id})
|
||||
if not chat:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
async def add_served_chat(chat_id: int):
|
||||
is_served = await is_served_chat(chat_id)
|
||||
if is_served:
|
||||
return
|
||||
return await chatsdb.insert_one({"chat_id": chat_id})
|
||||
|
||||
|
||||
async def remove_served_chat(chat_id: int):
|
||||
is_served = await is_served_chat(chat_id)
|
||||
if not is_served:
|
||||
return
|
||||
return await chatsdb.delete_one({"chat_id": chat_id})
|
8
driver/database/dblocal.py
Normal file
8
driver/database/dblocal.py
Normal file
@ -0,0 +1,8 @@
|
||||
""" mongo database """
|
||||
|
||||
from motor.motor_asyncio import AsyncIOMotorClient as Bot
|
||||
from config import MONGO_DB_URI as tmo
|
||||
|
||||
|
||||
MONGODB_CLI = Bot(tmo)
|
||||
db = MONGODB_CLI.program
|
32
driver/database/dbpunish.py
Normal file
32
driver/database/dbpunish.py
Normal file
@ -0,0 +1,32 @@
|
||||
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})
|
Loading…
Reference in New Issue
Block a user