forked from swatv3nub/PyrogramBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatsdb
More file actions
36 lines (26 loc) · 814 Bytes
/
chatsdb
File metadata and controls
36 lines (26 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from PyrogramBot import db
from typing import List
chatsdb = db.chats
async def is_in_chat(chat_id: int) -> bool:
chat = await chatsdb.find_one({"chat_id": chat_id})
if not chat:
return False
return True
async def get_in_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 add_in_chat(chat_id: int):
is_in = await is_in_chat(chat_id)
if is_in:
return
return await chatsdb.insert_one({"chat_id": chat_id})
async def remove_in_chat(chat_id: int):
is_in = await is_in_chat(chat_id)
if not is_in:
return
return await chatsdb.delete_one({"chat_id": chat_id})