diff --git a/dist/ba_root/mods/Currency/Commands/Command_Objects/__pycache__/data_functions.cpython-38.opt-1.pyc b/dist/ba_root/mods/Currency/Commands/Command_Objects/__pycache__/data_functions.cpython-38.opt-1.pyc index 05c1bf9..835b572 100644 Binary files a/dist/ba_root/mods/Currency/Commands/Command_Objects/__pycache__/data_functions.cpython-38.opt-1.pyc and b/dist/ba_root/mods/Currency/Commands/Command_Objects/__pycache__/data_functions.cpython-38.opt-1.pyc differ diff --git a/dist/ba_root/mods/Currency/Commands/Command_Objects/data_functions.py b/dist/ba_root/mods/Currency/Commands/Command_Objects/data_functions.py index db946e2..c2c9a50 100644 --- a/dist/ba_root/mods/Currency/Commands/Command_Objects/data_functions.py +++ b/dist/ba_root/mods/Currency/Commands/Command_Objects/data_functions.py @@ -17,56 +17,48 @@ def balance_call(userid : str, clientid : int): users = get_bank_data() name = client_to_name(clientid) - cash_amt = users[str(userid)]["cash"] - bank_cash_amt = users[str(userid)]["bank_cash"] - bank_space = users[str(userid)]["bank_space"] + PlayerData = get_player_data(userid) - balance = CLstr("English", "balance").format(str(name), str(cash_amt), str(bank_cash_amt), str(bank_space)) + balance = CLstr("English", "balance").format(str(name), str(PlayerData[0]), str(PlayerData[1]), str(PlayerData[2])) send(balance, clientid) + def beg_call(userid : str, clientid : int): open_account(userid) earned = get_random_cash() - users = get_bank_data() - - users[str(userid)]["cash"] += earned - cash = users[str(userid)]["cash"] + update_bank(userid, earned, "cash", type_only=True) + cash = get_player_data(userid)[0] donator = get_random_donator() send(CLstr("English", "beg").format(donator, earned, cash), clientid) - commit(users) + def withdraw_call(userid : str, args : int, clientid : int): open_account(userid) - - users = get_bank_data() withd = int(args[0]) if cheack_withd(userid, withd, clientid): return - users[str(userid)]["cash"] += withd - users[str(userid)]["bank_cash"] -= withd - commit(users) + update_bank(userid, withd) + send(CLstr("English", "withdraw").format(withd), clientid) + def deposit_call(userid : str, args : int, clientid : int): open_account(userid) - - users = get_bank_data() dep = int(args[0]) if cheack_cash_and_space(userid, dep, clientid): return - users[str(userid)]["cash"] -= dep - users[str(userid)]["bank_cash"] += dep - commit(users) + update_bank(userid, dep, "bank") + send(CLstr("English", "deposit").format(dep), clientid) \ No newline at end of file diff --git a/dist/ba_root/mods/Currency/Data/bank.json b/dist/ba_root/mods/Currency/Data/bank.json index 125b81e..565c4f0 100644 --- a/dist/ba_root/mods/Currency/Data/bank.json +++ b/dist/ba_root/mods/Currency/Data/bank.json @@ -1,8 +1,8 @@ { "None": { - "cash": 2620, + "cash": 3402, "bank_space": 100, - "bank_cash": 0 + "bank_cash": 10 }, "pb-IF4VAk4a": { "cash": 0, diff --git a/dist/ba_root/mods/Currency/Data/textes.json b/dist/ba_root/mods/Currency/Data/textes.json index bffb1dc..d755262 100644 --- a/dist/ba_root/mods/Currency/Data/textes.json +++ b/dist/ba_root/mods/Currency/Data/textes.json @@ -3,7 +3,8 @@ "errors":{ "short_space":"You don't have that much space", "short_ammount":"You don't have that much cash", - "short_bank_cash":"you don't have that much money in bank" + "short_bank_cash":"you don't have that much money in bank", + "bank_space_error":"get space in bank first" }, "balance": "|| {} | Cash - {} | Bank- {}/{} ||", "beg":"{} gave you {} now you have {} coins", diff --git a/dist/ba_root/mods/Currency/Handlers/__pycache__/bank_handler.cpython-38.opt-1.pyc b/dist/ba_root/mods/Currency/Handlers/__pycache__/bank_handler.cpython-38.opt-1.pyc index 9d60e46..4f19a67 100644 Binary files a/dist/ba_root/mods/Currency/Handlers/__pycache__/bank_handler.cpython-38.opt-1.pyc and b/dist/ba_root/mods/Currency/Handlers/__pycache__/bank_handler.cpython-38.opt-1.pyc differ diff --git a/dist/ba_root/mods/Currency/Handlers/bank_handler.py b/dist/ba_root/mods/Currency/Handlers/bank_handler.py index 91d1c76..ad61bc9 100644 --- a/dist/ba_root/mods/Currency/Handlers/bank_handler.py +++ b/dist/ba_root/mods/Currency/Handlers/bank_handler.py @@ -14,6 +14,19 @@ def get_bank_data(): +def get_player_data(accountid : str): + users = get_bank_data() + + cash = users[str(accountid)]["cash"] + bank_space = users[str(accountid)]["bank_space"] + bank_cash = users[str(accountid)]["bank_cash"] + + PlayerData = cash, bank_cash, bank_space + + return PlayerData + + + def commit(data): with open(bank_path, "w") as f: json.dump(data, f, indent=2) @@ -35,17 +48,45 @@ def open_account(accountid : str): +def update_bank(userid, ammount : int=0, type="cash", type_only=False): + users = get_bank_data() + + if type == "cash": + users[str(userid)]["cash"] += ammount + if type_only: + commit(users) + return + users[str(userid)]["bank_cash"] -= ammount + + commit(users) + + if type == "bank": + users[str(userid)]["cash"] -= ammount + if type_only: + commit(users) + return + users[str(userid)]["bank_cash"] += ammount + + commit(users) + + def cheack_cash_and_space(userid, ammount : int, clientid : int): users = get_bank_data() cash_amt = users[str(userid)]["cash"] + bank_cash = users[str(userid)]["bank_cash"] bank_space = users[str(userid)]["bank_space"] if bank_space < ammount: send(Errorstr("English", "short_space"), clientid) return True + + if bank_space < bank_cash + ammount: + send(Errorstr("English", "bank_space_error"), clientid) + return True + if cash_amt < ammount: send(Errorstr("English", "short_ammount"), clientid) return True