Spaces:
Runtime error
Runtime error
Commit
•
7858524
1
Parent(s):
d1e8493
Upload 3 files
Browse files- database/access.py +5 -0
- database/adduser.py +8 -0
- database/database.py +41 -0
database/access.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from config import Config
|
3 |
+
from database.database import Database
|
4 |
+
|
5 |
+
clinton = Database(Config.DATABASE_URL, Config.SESSION_NAME)
|
database/adduser.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pyrogram import Client
|
2 |
+
from database.access import clinton
|
3 |
+
from pyrogram.types import Message
|
4 |
+
|
5 |
+
|
6 |
+
async def AddUser(bot: Client, update: Message):
|
7 |
+
if not await clinton.is_user_exist(update.from_user.id):
|
8 |
+
await clinton.add_user(update.from_user.id)
|
database/database.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# (c) @AbirHasan2005 | X-Noid | @DC4_WARRIOR
|
2 |
+
|
3 |
+
import datetime
|
4 |
+
import motor.motor_asyncio
|
5 |
+
|
6 |
+
class Database:
|
7 |
+
|
8 |
+
def __init__(self, uri, database_name):
|
9 |
+
self._client = motor.motor_asyncio.AsyncIOMotorClient(uri)
|
10 |
+
self.clinton = self._client[database_name]
|
11 |
+
self.col = self.clinton.USERS
|
12 |
+
|
13 |
+
def new_user(self, id):
|
14 |
+
return dict(id=id, thumbnail=None)
|
15 |
+
|
16 |
+
|
17 |
+
async def add_user(self, id):
|
18 |
+
user = self.new_user(id)
|
19 |
+
await self.col.insert_one(user)
|
20 |
+
|
21 |
+
async def is_user_exist(self, id):
|
22 |
+
user = await self.col.find_one({'id': int(id)})
|
23 |
+
return True if user else False
|
24 |
+
|
25 |
+
async def total_users_count(self):
|
26 |
+
count = await self.col.count_documents({})
|
27 |
+
return count
|
28 |
+
|
29 |
+
async def get_all_users(self):
|
30 |
+
all_users = self.col.find({})
|
31 |
+
return all_users
|
32 |
+
|
33 |
+
async def delete_user(self, user_id):
|
34 |
+
await self.col.delete_many({'id': int(user_id)})
|
35 |
+
|
36 |
+
async def set_thumbnail(self, id, thumbnail):
|
37 |
+
await self.col.update_one({'id': id}, {'$set': {'thumbnail': thumbnail}})
|
38 |
+
|
39 |
+
async def get_thumbnail(self, id):
|
40 |
+
user = await self.col.find_one({'id': int(id)})
|
41 |
+
return user.get('thumbnail', None)
|