-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjvdb.py
63 lines (54 loc) · 2.28 KB
/
jvdb.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Author: Jigarvarma2005
from motor import motor_asyncio
class MongoDB:
def __init__(self, url: str):
self.client = motor_asyncio.AsyncIOMotorClient(url)
self.db = self.client.giveawaybot
self.mygiveaways = self.db.mygiveaways
async def get_giveawayid(self, userid: int):
user = await self.mygiveaways.find_one({"_id": userid})
return self.db[str(userid)] if user != None else None
async def add_giveawayid(self, userid: int):
if not (await self.mygiveaways.find_one({"_id": userid})):
await self.mygiveaways.insert_one({"_id": userid})
return self.db[str(userid)]
else:
return None
async def delete_giveawayid(self, userid: int):
user = await self.mygiveaways.find_one({"_id": userid})
if user != None:
await self.mygiveaways.delete_one(user)
userDb = self.db[str(userid)]
await userDb.drop()
return True
else:
return None
async def get_giveaway_users(self, userid: int):
userDb = await self.get_giveawayid(userid)
if userDb is None:
return None
giveaway = userDb.find({})
if giveaway is None:
return None
count = await userDb.count_documents({})
return await giveaway.to_list(count)
async def add_giveaway(self, userid: int, winners: int, msg_text: str, giveaway_text: str):
userDb = await self.add_giveawayid(userid)
if userDb != None:
await userDb.insert_one({"_id": "data", "winners": winners, "msg_text": msg_text, "giveaway_text": giveaway_text})
return True
else:
return None
async def get_giveaway_users_count(self, userid: int):
userDb = await self.get_giveawayid(userid)
if userDb != None:
return giveaway if (giveaway := await userDb.count_documents({})) else None
else:
return None
async def add_giveaway_user(self, giveawayId: int, userId: int):
userDb = await self.get_giveawayid(giveawayId)
if userDb != None:
if (await userDb.find_one({"_id": userId})):
return None
await userDb.insert_one({"_id": userId})
return userDb