From 4ab89f48b671fc0cb7d022bfd9d70dc006682798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CA=99=E1=B4=80=E1=B4=85=20=E1=B4=8D=E1=B4=9C=C9=B4?= =?UTF-8?q?=E1=B4=85=E1=B4=80=20=F0=9F=8C=B8?= <154504921+Badhacker98@users.noreply.github.com> Date: Thu, 10 Oct 2024 23:21:32 +0530 Subject: [PATCH] Create chats.py --- shizuchat/database/chats.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 shizuchat/database/chats.py diff --git a/shizuchat/database/chats.py b/shizuchat/database/chats.py new file mode 100644 index 0000000..6f898f2 --- /dev/null +++ b/shizuchat/database/chats.py @@ -0,0 +1,34 @@ +from shizuchat import db + +chatsdb = db.chatsdb + + +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})