Skip to content

Commit

Permalink
Create chats.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Badhacker98 authored Oct 10, 2024
1 parent 3efaddc commit 4ab89f4
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions shizuchat/database/chats.py
Original file line number Diff line number Diff line change
@@ -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})

0 comments on commit 4ab89f4

Please sign in to comment.