GoldyBot.database.member.money
1from __future__ import annotations 2 3import GoldyBot 4from ...objects.currency import Currency 5 6class Money(): 7 """Subclass for managing money in member database class.""" 8 def __init__(self, member) -> None: 9 self.actual_member:GoldyBot.Member = member 10 11 async def get_money(self, currency_class:Currency) -> int: 12 """Returns the amount of money this member has of that currency.""" 13 currency = currency_class 14 15 try: 16 member_data = await self.actual_member.get_member_data() 17 return int(member_data[self.actual_member.member_id][currency.code_name]) 18 except KeyError: 19 return currency.default_bal 20 21 async def give_money(self, currency_class:Currency, amount:int|float) -> bool: 22 """Gives the member the specified amount of money on that specified currency.""" 23 currency = currency_class 24 25 # Add to previous bal in database. 26 result = await self.actual_member.database.edit("global", {"_id":int(self.actual_member.member_id)}, { 27 self.actual_member.member_id: { 28 currency.code_name: (await self.get_money(currency) + amount) 29 } 30 }) 31 32 return result 33 34 async def take_money(self, currency_class:Currency, amount:int|float) -> bool: 35 """Takes from the member a specified amount of money on that specified currency.""" 36 currency = currency_class 37 38 # Take from previous bal in database. 39 result = await self.actual_member.database.edit("global", {"_id":int(self.actual_member.member_id)}, { 40 self.actual_member.member_id: { 41 currency.code_name: (await self.get_money(currency) - amount) 42 } 43 }) 44 45 return result
class
Money:
7class Money(): 8 """Subclass for managing money in member database class.""" 9 def __init__(self, member) -> None: 10 self.actual_member:GoldyBot.Member = member 11 12 async def get_money(self, currency_class:Currency) -> int: 13 """Returns the amount of money this member has of that currency.""" 14 currency = currency_class 15 16 try: 17 member_data = await self.actual_member.get_member_data() 18 return int(member_data[self.actual_member.member_id][currency.code_name]) 19 except KeyError: 20 return currency.default_bal 21 22 async def give_money(self, currency_class:Currency, amount:int|float) -> bool: 23 """Gives the member the specified amount of money on that specified currency.""" 24 currency = currency_class 25 26 # Add to previous bal in database. 27 result = await self.actual_member.database.edit("global", {"_id":int(self.actual_member.member_id)}, { 28 self.actual_member.member_id: { 29 currency.code_name: (await self.get_money(currency) + amount) 30 } 31 }) 32 33 return result 34 35 async def take_money(self, currency_class:Currency, amount:int|float) -> bool: 36 """Takes from the member a specified amount of money on that specified currency.""" 37 currency = currency_class 38 39 # Take from previous bal in database. 40 result = await self.actual_member.database.edit("global", {"_id":int(self.actual_member.member_id)}, { 41 self.actual_member.member_id: { 42 currency.code_name: (await self.get_money(currency) - amount) 43 } 44 }) 45 46 return result
Subclass for managing money in member database class.
12 async def get_money(self, currency_class:Currency) -> int: 13 """Returns the amount of money this member has of that currency.""" 14 currency = currency_class 15 16 try: 17 member_data = await self.actual_member.get_member_data() 18 return int(member_data[self.actual_member.member_id][currency.code_name]) 19 except KeyError: 20 return currency.default_bal
Returns the amount of money this member has of that currency.
async def
give_money( self, currency_class: GoldyBot.objects.currency.Currency, amount: int | float) -> bool:
22 async def give_money(self, currency_class:Currency, amount:int|float) -> bool: 23 """Gives the member the specified amount of money on that specified currency.""" 24 currency = currency_class 25 26 # Add to previous bal in database. 27 result = await self.actual_member.database.edit("global", {"_id":int(self.actual_member.member_id)}, { 28 self.actual_member.member_id: { 29 currency.code_name: (await self.get_money(currency) + amount) 30 } 31 }) 32 33 return result
Gives the member the specified amount of money on that specified currency.
async def
take_money( self, currency_class: GoldyBot.objects.currency.Currency, amount: int | float) -> bool:
35 async def take_money(self, currency_class:Currency, amount:int|float) -> bool: 36 """Takes from the member a specified amount of money on that specified currency.""" 37 currency = currency_class 38 39 # Take from previous bal in database. 40 result = await self.actual_member.database.edit("global", {"_id":int(self.actual_member.member_id)}, { 41 self.actual_member.member_id: { 42 currency.code_name: (await self.get_money(currency) - amount) 43 } 44 }) 45 46 return result
Takes from the member a specified amount of money on that specified currency.