-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
52 lines (44 loc) · 1.5 KB
/
database.py
File metadata and controls
52 lines (44 loc) · 1.5 KB
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
48
49
50
51
52
from motor.motor_asyncio import AsyncIOMotorClient
from config import Config
class Database:
def __init__(self):
self.client = AsyncIOMotorClient(Config.MONGODB_URI)
self.db = self.client['file_renamer_bot']
self.users = self.db['users']
self.settings = self.db['settings']
async def add_user(self, user_id):
user = await self.users.find_one({'user_id': user_id})
if not user:
await self.users.insert_one({
'user_id': user_id,
'thumbnail': None,
'prefix': '',
'suffix': '',
'metadata': {}
})
async def get_user(self, user_id):
return await self.users.find_one({'user_id': user_id})
async def set_thumbnail(self, user_id, file_id):
await self.users.update_one(
{'user_id': user_id},
{'$set': {'thumbnail': file_id}},
upsert=True
)
async def del_thumbnail(self, user_id):
await self.users.update_one(
{'user_id': user_id},
{'$set': {'thumbnail': None}}
)
async def set_prefix(self, user_id, prefix):
await self.users.update_one(
{'user_id': user_id},
{'$set': {'prefix': prefix}},
upsert=True
)
async def set_suffix(self, user_id, suffix):
await self.users.update_one(
{'user_id': user_id},
{'$set': {'suffix': suffix}},
upsert=True
)
db = Database()