From 410744c6e100295818a546d0b164354543ef05aa Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Wed, 9 Feb 2022 06:11:05 +0700 Subject: [PATCH] create database for generating calls and music data --- driver/database/dbqueue.py | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 driver/database/dbqueue.py diff --git a/driver/database/dbqueue.py b/driver/database/dbqueue.py new file mode 100644 index 0000000..5e68c2e --- /dev/null +++ b/driver/database/dbqueue.py @@ -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})