-
Notifications
You must be signed in to change notification settings - Fork 27
/
database.py
47 lines (38 loc) · 1.05 KB
/
database.py
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
37
38
39
40
41
42
43
44
45
46
47
from pymongo import MongoClient
from configs import cfg
client = MongoClient(cfg.MONGO_URI)
users = client['main']['users']
groups = client['main']['groups']
def already_db(user_id):
user = users.find_one({"user_id" : str(user_id)})
if not user:
return False
return True
def already_dbg(chat_id):
group = groups.find_one({"chat_id" : str(chat_id)})
if not group:
return False
return True
def add_user(user_id):
in_db = already_db(user_id)
if in_db:
return
return users.insert_one({"user_id": str(user_id)})
def remove_user(user_id):
in_db = already_db(user_id)
if not in_db:
return
return users.delete_one({"user_id": str(user_id)})
def add_group(chat_id):
in_db = already_dbg(chat_id)
if in_db:
return
return groups.insert_one({"chat_id": str(chat_id)})
def all_users():
user = users.find({})
usrs = len(list(user))
return usrs
def all_groups():
group = groups.find({})
grps = len(list(group))
return grps