Removed Currency folder.

This commit is contained in:
pranav-1711 2022-02-14 13:29:59 +05:30
parent e566a7463f
commit 15935b8bc6
10 changed files with 0 additions and 303 deletions

View file

@ -1,64 +0,0 @@
""" store functions executed when chat command are called """
import ba, _ba, json, random
from Currency.Handlers.bank_handler import *
from Currency.Handlers.ba_get_player_data import *
#from Currency.Handlers.cooldown_manager import *
from Currency.Handlers.CLstr import CLstr, Errorstr
from .fun import get_random_donator, get_random_cash
def balance_call(userid : str, clientid : int):
open_account(userid)
users = get_bank_data()
name = client_to_name(clientid)
PlayerData = get_player_data(userid)
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()
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)
def withdraw_call(userid : str, args : int, clientid : int):
open_account(userid)
withd = int(args[0])
if cheack_withd(userid, withd, clientid):
return
update_bank(userid, withd)
send(CLstr("English", "withdraw").format(withd), clientid)
def deposit_call(userid : str, args : int, clientid : int):
open_account(userid)
dep = int(args[0])
if cheack_cash_and_space(userid, dep, clientid):
return
update_bank(userid, dep, "bank")
send(CLstr("English", "deposit").format(dep), clientid)

View file

@ -1,17 +0,0 @@
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)

View file

@ -1,20 +0,0 @@
""" 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, clientid)
elif cmd in ['with', 'withdraw']:
withdraw_call(accountid, args, clientid)
elif cmd in ['dep', 'deposite']:
deposit_call(accountid, args, clientid)

View file

@ -1,12 +0,0 @@
{
"None": {
"cash": 3402,
"bank_space": 100,
"bank_cash": 10
},
"pb-IF4VAk4a": {
"cash": 0,
"bank_space": 100,
"bank_cash": 0
}
}

View file

@ -1,14 +0,0 @@
{
"English": {
"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",
"bank_space_error":"get space in bank first"
},
"balance": "|| {} | Cash - {} | Bank- {}/{} ||",
"beg":"{} gave you {} now you have {} coins",
"deposit":"deposited {}",
"withdraw": "withdrew {}"
}
}

View file

@ -1,18 +0,0 @@
import ba, _ba, json
textes_path = _ba.env()['python_directory_user']+'/Currency/Data/textes.json'
def CLstr(language, text):
with open(textes_path, 'r') as f:
textes = json.load(f)
text = textes[language][text]
return text
def Errorstr(language, text):
with open(textes_path, 'r') as f:
textes = json.load(f)
t = textes[language]["errors"][text]
return t

View file

@ -1,38 +0,0 @@
""" 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
def send(msg, clientid):
_ba.chatmessage(str(msg), clients=[clientid])
_ba.screenmessage(str(msg), transient=True, clients=[clientid])
def senderror(msg, clientid):
_ba.chatmessage(str(msg), clients=[clientid], sender_override = "Use[server]")
_ba.screenmessage("Use[server] " + str(msg), transient=True, clients=[clientid])

View file

@ -1,105 +0,0 @@
""" helperfunctions for save lot of lines of code """
import ba, _ba, json
from .ba_get_player_data import send
from .CLstr import Errorstr
bank_path = _ba.env()['python_directory_user']+'/Currency/Data/bank.json'
def get_bank_data():
with open(bank_path, 'r') as f:
users = json.load(f)
return users
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)
def open_account(accountid : str):
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 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
def cheack_withd(userid, ammount : int, clientid : int):
users = get_bank_data()
bank_cash = users[str(userid)]["bank_cash"]
if bank_cash < ammount:
send(Errorstr("English", "short_bank_cash"), clientid)
return True

View file

@ -1 +0,0 @@
""" cooldown manager """"

View file

@ -1,14 +0,0 @@
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)