create database

for generating calls and music data
This commit is contained in:
levina 2022-02-09 06:11:05 +07:00 committed by GitHub
parent bf7f83f324
commit 410744c6e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,58 @@
from typing import Dict, List, Union
from driver.database.dblocal import db
pytgdb = db.pytg
admindb = db.admin
async def get_active_chats() -> list:
chats = pytgdb.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_active_chat(chat_id: int) -> bool:
chat = await pytgdb.find_one({"chat_id": chat_id})
if not chat:
return False
return True
async def add_active_chat(chat_id: int):
is_served = await is_active_chat(chat_id)
if is_served:
return
return await pytgdb.insert_one({"chat_id": chat_id})
async def remove_active_chat(chat_id: int):
is_served = await is_active_chat(chat_id)
if not is_served:
return
return await pytgdb.delete_one({"chat_id": chat_id})
async def is_music_playing(chat_id: int) -> bool:
chat = await admindb.find_one({"chat_id_toggle": chat_id})
if not chat:
return True
return False
async def music_on(chat_id: int):
is_on = await is_music_playing(chat_id)
if is_on:
return
return await admindb.delete_one({"chat_id_toggle": chat_id})
async def music_off(chat_id: int):
is_on = await is_music_playing(chat_id)
if not is_on:
return
return await admindb.insert_one({"chat_id_toggle": chat_id})