MCPcopy Create free account
hub / github.com/VJBots/VJ-Forward-Bot / Db

Class Db

database.py:4–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2from config import Config
3
4class Db:
5
6 def __init__(self, uri, database_name):
7 self._client = motor.motor_asyncio.AsyncIOMotorClient(uri)
8 self.db = self._client[database_name]
9 self.bot = self.db.bots
10 self.userbot = self.db.userbot
11 self.col = self.db.users
12 self.nfy = self.db.notify
13 self.chl = self.db.channels
14
15 def new_user(self, id, name):
16 return dict(
17 id = id,
18 name = name,
19 ban_status=dict(
20 is_banned=False,
21 ban_reason="",
22 ),
23 )
24
25 async def add_user(self, id, name):
26 user = self.new_user(id, name)
27 await self.col.insert_one(user)
28
29 async def is_user_exist(self, id):
30 user = await self.col.find_one({'id':int(id)})
31 return bool(user)
32
33 async def total_users_count(self):
34 count = await self.col.count_documents({})
35 return count
36
37 async def total_users_bots_count(self):
38 bcount = await self.bot.count_documents({})
39 count = await self.col.count_documents({})
40 return count, bcount
41
42 async def remove_ban(self, id):
43 ban_status = dict(
44 is_banned=False,
45 ban_reason=''
46 )
47 await self.col.update_one({'id': id}, {'$set': {'ban_status': ban_status}})
48
49 async def ban_user(self, user_id, ban_reason="No Reason"):
50 ban_status = dict(
51 is_banned=True,
52 ban_reason=ban_reason
53 )
54 await self.col.update_one({'id': user_id}, {'$set': {'ban_status': ban_status}})
55
56 async def get_ban_status(self, id):
57 default = dict(
58 is_banned=False,
59 ban_reason=''
60 )
61 user = await self.col.find_one({'id':int(id)})

Callers 1

database.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected