GoldyBot.database.member

 1import random
 2
 3import GoldyBot
 4
 5from .money import Money
 6
 7class Member(Money):
 8    """Creates member database interface with ctx to allow for easy grabbing of member data."""
 9    def __init__(self, ctx, member) -> None:
10        self.ctx = ctx
11        self.actual_member:GoldyBot.member.Member = member
12
13        self.database = GoldyBot.cache.database()
14
15        super().__init__(member)
16
17    async def get_member_data(self):
18        """Returns member's database collection."""
19        # Generate document if member doesn't exists in database.
20        await self.setup()
21
22        # Return member data.
23        return await self.database.find_one("global", {"_id":int(self.actual_member.member_id)})
24
25    async def edit_member_data(self, new_data:dict) -> bool:
26        """Updates member's database collection."""
27        # Generate document if member doesn't exists in database.
28        await self.setup()
29
30        # Update member data.
31        return await self.actual_member.database.edit("global", {"_id":int(self.actual_member.member_id)}, new_data)
32
33
34    async def setup(self):
35        """Makes sure this member is setup in global and guild collection."""
36
37        # Global setup if member does not exist in global collection.
38        if await self.database.find_one("global", {"_id":int(self.actual_member.member_id)}) == None:
39            await self.database.insert("global", data={
40                "_id":int(self.actual_member.member_id),
41
42                f"{self.actual_member.member_id}" : {}
43            })
44
45        # Guild setup if member does not exist in guild collection.
46        if await self.database.find_one(GoldyBot.cache.FindGuilds().find_object_by_id(self.ctx.guild.id).database_collection_name, {"_id":int(self.actual_member.member_id)}) == None:
47            await self.database.insert(GoldyBot.cache.FindGuilds().find_object_by_id(self.ctx.guild.id).database_collection_name, data={
48                "_id":int(self.actual_member.member_id),
49
50                f"{self.actual_member.member_id}" : {}
51            })
class Member(GoldyBot.database.member.money.Money):
 8class Member(Money):
 9    """Creates member database interface with ctx to allow for easy grabbing of member data."""
10    def __init__(self, ctx, member) -> None:
11        self.ctx = ctx
12        self.actual_member:GoldyBot.member.Member = member
13
14        self.database = GoldyBot.cache.database()
15
16        super().__init__(member)
17
18    async def get_member_data(self):
19        """Returns member's database collection."""
20        # Generate document if member doesn't exists in database.
21        await self.setup()
22
23        # Return member data.
24        return await self.database.find_one("global", {"_id":int(self.actual_member.member_id)})
25
26    async def edit_member_data(self, new_data:dict) -> bool:
27        """Updates member's database collection."""
28        # Generate document if member doesn't exists in database.
29        await self.setup()
30
31        # Update member data.
32        return await self.actual_member.database.edit("global", {"_id":int(self.actual_member.member_id)}, new_data)
33
34
35    async def setup(self):
36        """Makes sure this member is setup in global and guild collection."""
37
38        # Global setup if member does not exist in global collection.
39        if await self.database.find_one("global", {"_id":int(self.actual_member.member_id)}) == None:
40            await self.database.insert("global", data={
41                "_id":int(self.actual_member.member_id),
42
43                f"{self.actual_member.member_id}" : {}
44            })
45
46        # Guild setup if member does not exist in guild collection.
47        if await self.database.find_one(GoldyBot.cache.FindGuilds().find_object_by_id(self.ctx.guild.id).database_collection_name, {"_id":int(self.actual_member.member_id)}) == None:
48            await self.database.insert(GoldyBot.cache.FindGuilds().find_object_by_id(self.ctx.guild.id).database_collection_name, data={
49                "_id":int(self.actual_member.member_id),
50
51                f"{self.actual_member.member_id}" : {}
52            })

Creates member database interface with ctx to allow for easy grabbing of member data.

Member(ctx, member)
10    def __init__(self, ctx, member) -> None:
11        self.ctx = ctx
12        self.actual_member:GoldyBot.member.Member = member
13
14        self.database = GoldyBot.cache.database()
15
16        super().__init__(member)
async def get_member_data(self):
18    async def get_member_data(self):
19        """Returns member's database collection."""
20        # Generate document if member doesn't exists in database.
21        await self.setup()
22
23        # Return member data.
24        return await self.database.find_one("global", {"_id":int(self.actual_member.member_id)})

Returns member's database collection.

async def edit_member_data(self, new_data: dict) -> bool:
26    async def edit_member_data(self, new_data:dict) -> bool:
27        """Updates member's database collection."""
28        # Generate document if member doesn't exists in database.
29        await self.setup()
30
31        # Update member data.
32        return await self.actual_member.database.edit("global", {"_id":int(self.actual_member.member_id)}, new_data)

Updates member's database collection.

async def setup(self):
35    async def setup(self):
36        """Makes sure this member is setup in global and guild collection."""
37
38        # Global setup if member does not exist in global collection.
39        if await self.database.find_one("global", {"_id":int(self.actual_member.member_id)}) == None:
40            await self.database.insert("global", data={
41                "_id":int(self.actual_member.member_id),
42
43                f"{self.actual_member.member_id}" : {}
44            })
45
46        # Guild setup if member does not exist in guild collection.
47        if await self.database.find_one(GoldyBot.cache.FindGuilds().find_object_by_id(self.ctx.guild.id).database_collection_name, {"_id":int(self.actual_member.member_id)}) == None:
48            await self.database.insert(GoldyBot.cache.FindGuilds().find_object_by_id(self.ctx.guild.id).database_collection_name, data={
49                "_id":int(self.actual_member.member_id),
50
51                f"{self.actual_member.member_id}" : {}
52            })

Makes sure this member is setup in global and guild collection.