added some stuf

This commit is contained in:
snowman1711 2021-04-14 22:05:43 +05:30
parent b582230e7e
commit ad0449da87
13 changed files with 140 additions and 32 deletions

View file

@ -1,16 +1,17 @@
""" 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 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, clientid):
def balance_call(userid : str, clientid : int):
open_account(userid)
users = get_bank_data()
@ -20,23 +21,52 @@ def balance_call(userid, clientid):
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)
balance = CLstr("English", "balance").format(str(name), str(cash_amt), str(bank_cash_amt), str(bank_space))
send(balance, clientid)
def beg_call(userid):
def beg_call(userid : str, clientid : int):
open_account(userid)
earned = get_random_cash()
users = get_bank_data()
user = users[str(userid)]
user["cash"] += earned
cash_amt = user["cash"]
users[str(userid)]["cash"] += earned
cash = users[str(userid)]["cash"]
donator = get_random_donator()
send(f'{donator} gave you {earned} now you have {cash_amt} coins')
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)
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)
send(CLstr("English", "deposit").format(dep), clientid)

View file

@ -10,4 +10,11 @@ def on_command(cmd, args, accountid, clientid):
balance_call(accountid, clientid)
elif cmd == 'beg':
beg_call(accountid)
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,11 +1,11 @@
{
"None": {
"cash": 1421,
"cash": 2620,
"bank_space": 100,
"bank_cash": 0
},
"pb-IF4VAk4a": {
"cash": 297,
"cash": 0,
"bank_space": 100,
"bank_cash": 0
}

View file

@ -0,0 +1,13 @@
{
"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"
},
"balance": "|| {} | Cash - {} | Bank- {}/{} ||",
"beg":"{} gave you {} now you have {} coins",
"deposit":"deposited {}",
"withdraw": "withdrew {}"
}
}

View file

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

@ -22,3 +22,17 @@ def client_to_display_string(client_id):
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,28 +1,12 @@
""" 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 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)
@ -36,3 +20,45 @@ def commit(data):
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 cheack_cash_and_space(userid, ammount : int, clientid : int):
users = get_bank_data()
cash_amt = users[str(userid)]["cash"]
bank_space = users[str(userid)]["bank_space"]
if bank_space < ammount:
send(Errorstr("English", "short_space"), 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