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 new file mode 100644 index 0000000..ceec04e Binary files /dev/null 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/__pycache__/fun.cpython-38.opt-1.pyc b/dist/ba_root/mods/Currency/Commands/Command_Objects/__pycache__/fun.cpython-38.opt-1.pyc new file mode 100644 index 0000000..51bf239 Binary files /dev/null and b/dist/ba_root/mods/Currency/Commands/Command_Objects/__pycache__/fun.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 new file mode 100644 index 0000000..f506282 --- /dev/null +++ b/dist/ba_root/mods/Currency/Commands/Command_Objects/data_functions.py @@ -0,0 +1,42 @@ +""" store functions executed when chat command are called """ +import ba, _ba, json, random +from _ba import chatmessage as send +from _ba import screenmessage as screenmsg +from Currency.Handlers.bank_handler import * +from Currency.Handlers.ba_get_player_data import * +from Currency.Handlers.cooldown_manager import * +from .fun import get_random_donator, get_random_cash + + + + +def balance_call(userid, clientid): + open_account(userid) + + 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"] + + balance = '|| {} | Cash - {} | Bank- {}/{} ||'.format(str(name), str(cash_amt), str(bank_cash_amt), str(bank_space)) + send(balance) + + + +def beg_call(userid): + open_account(userid) + earned = get_random_cash() + + users = get_bank_data() + user = users[str(userid)] + + user["cash"] += earned + cash_amt = user["cash"] + donator = get_random_donator() + send(f'{donator} gave you {earned} now you have {cash_amt} coins') + + commit(users) + + diff --git a/dist/ba_root/mods/Currency/Commands/Command_Objects/fun.py b/dist/ba_root/mods/Currency/Commands/Command_Objects/fun.py new file mode 100644 index 0000000..f98a4ce --- /dev/null +++ b/dist/ba_root/mods/Currency/Commands/Command_Objects/fun.py @@ -0,0 +1,17 @@ +import random + +donators_list = [ +'Eggs broke and', +'pranav', +'your mom', +'saitama', +'one simp', +'idiot', +'mr smoothy' +] + +def get_random_donator(): + return random.choice(donators_list) + +def get_random_cash(): + return random.randrange(80) diff --git a/dist/ba_root/mods/Currency/Commands/__pycache__/chat_commands.cpython-38.opt-1.pyc b/dist/ba_root/mods/Currency/Commands/__pycache__/chat_commands.cpython-38.opt-1.pyc new file mode 100644 index 0000000..f014b83 Binary files /dev/null and b/dist/ba_root/mods/Currency/Commands/__pycache__/chat_commands.cpython-38.opt-1.pyc differ diff --git a/dist/ba_root/mods/Currency/Commands/chat_commands.py b/dist/ba_root/mods/Currency/Commands/chat_commands.py new file mode 100644 index 0000000..774a20e --- /dev/null +++ b/dist/ba_root/mods/Currency/Commands/chat_commands.py @@ -0,0 +1,13 @@ +""" check given command and executive the the cmd function from data functions""" + +import ba, _ba +from .Command_Objects.data_functions import * + + +def on_command(cmd, args, accountid, clientid): + + if cmd in ['coins', 'bal', 'balance', 'me']: + balance_call(accountid, clientid) + + elif cmd == 'beg': + beg_call(accountid) diff --git a/dist/ba_root/mods/Currency/Data/bank.json b/dist/ba_root/mods/Currency/Data/bank.json new file mode 100644 index 0000000..c36c22b --- /dev/null +++ b/dist/ba_root/mods/Currency/Data/bank.json @@ -0,0 +1,12 @@ +{ + "None": { + "cash": 1421, + "bank_space": 100, + "bank_cash": 0 + }, + "pb-IF4VAk4a": { + "cash": 297, + "bank_space": 100, + "bank_cash": 0 + } +} \ No newline at end of file diff --git a/dist/ba_root/mods/Currency/Handlers/__pycache__/ba_get_player_data.cpython-38.opt-1.pyc b/dist/ba_root/mods/Currency/Handlers/__pycache__/ba_get_player_data.cpython-38.opt-1.pyc new file mode 100644 index 0000000..a885830 Binary files /dev/null and b/dist/ba_root/mods/Currency/Handlers/__pycache__/ba_get_player_data.cpython-38.opt-1.pyc differ 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 new file mode 100644 index 0000000..5158109 Binary files /dev/null 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/__pycache__/cooldown_manager.cpython-38.opt-1.pyc b/dist/ba_root/mods/Currency/Handlers/__pycache__/cooldown_manager.cpython-38.opt-1.pyc new file mode 100644 index 0000000..31c4769 Binary files /dev/null and b/dist/ba_root/mods/Currency/Handlers/__pycache__/cooldown_manager.cpython-38.opt-1.pyc differ diff --git a/dist/ba_root/mods/Currency/Handlers/ba_get_player_data.py b/dist/ba_root/mods/Currency/Handlers/ba_get_player_data.py new file mode 100644 index 0000000..72b083b --- /dev/null +++ b/dist/ba_root/mods/Currency/Handlers/ba_get_player_data.py @@ -0,0 +1,24 @@ +""" retruns information of given user using client_id """ +import ba, _ba + +def client_to_account(client_id): + rost = _ba.get_game_roster() + for i in rost: + if i['client_id'] == client_id: + return i['account_id'] + return None + +def client_to_name(client_id): + rost = _ba.get_game_roster() + for i in rost: + if i['client_id'] == client_id: + return i['players'][0]['name_full'] + return None + + +def client_to_display_string(client_id): + rost = _ba.get_game_roster() + for i in rost: + if i['client_id'] == client_id: + return i['display_string'] + return None diff --git a/dist/ba_root/mods/Currency/Handlers/bank_handler.py b/dist/ba_root/mods/Currency/Handlers/bank_handler.py new file mode 100644 index 0000000..b2b594f --- /dev/null +++ b/dist/ba_root/mods/Currency/Handlers/bank_handler.py @@ -0,0 +1,38 @@ +""" helperfunctions for save lot of lines of code """ + +import ba, _ba, json + + +bank_path = _ba.env()['python_directory_user']+'/Currency/Data/bank.json' + + + + +def open_account(accountid): + users = get_bank_data() + + if str(accountid) in users: + return False + else: + users[str(accountid)] = {} + users[str(accountid)]["cash"] = 0 + users[str(accountid)]["bank_space"] = 100 + users[str(accountid)]["bank_cash"] = 0 + commit(users) + return True + + + +def get_bank_data(): + with open(bank_path, 'r') as f: + users = json.load(f) + return users + + + +def commit(data): + with open(bank_path, "w") as f: + json.dump(data, f, indent=2) + + + diff --git a/dist/ba_root/mods/Currency/Handlers/cooldown_manager.py b/dist/ba_root/mods/Currency/Handlers/cooldown_manager.py new file mode 100644 index 0000000..0bf7f0d --- /dev/null +++ b/dist/ba_root/mods/Currency/Handlers/cooldown_manager.py @@ -0,0 +1 @@ +""" cooldown manager """" \ No newline at end of file diff --git a/dist/ba_root/mods/Currency/__init__.py b/dist/ba_root/mods/Currency/__init__.py new file mode 100644 index 0000000..ad9c9da --- /dev/null +++ b/dist/ba_root/mods/Currency/__init__.py @@ -0,0 +1,14 @@ +from .Commands import chat_commands +from .Handlers.ba_get_player_data import client_to_account + + + +def main(msg, client_id): + command = msg.split(" ")[0] + + if command.startswith("."): + command = command.split(".")[1] + arguments = msg.split(" ")[1:] + accountid = client_to_account(client_id) + + chat_commands.on_command(command, arguments, accountid, client_id) \ No newline at end of file diff --git a/dist/ba_root/mods/Currency/__pycache__/__init__.cpython-38.opt-1.pyc b/dist/ba_root/mods/Currency/__pycache__/__init__.cpython-38.opt-1.pyc new file mode 100644 index 0000000..5f6f75b Binary files /dev/null and b/dist/ba_root/mods/Currency/__pycache__/__init__.cpython-38.opt-1.pyc differ