Bombsquad-Ballistica-Modded.../dist/ba_root/mods/playersData/pdata.py

228 lines
4.3 KiB
Python
Raw Normal View History

2021-03-31 13:02:42 +05:30
# Released under the MIT License. See LICENSE for details.
2021-04-10 16:33:19 +05:30
import _ba, os, json
roles = {}
data = {}
custom = {}
2021-04-07 03:58:40 +05:30
data_path = os.path.join(_ba.env()['python_directory_user'],"playersData" + os.sep)
2021-03-31 13:02:42 +05:30
2021-04-10 16:33:19 +05:30
2021-05-31 16:59:13 +05:30
def get_info(id):
with open(data_path+'profiles.json', 'r') as f:
profile = json.load(f)
return profile[id]
def add_profile(id,display_string,allprofiles,currentname):
f=open(data_path+"profiles.json","r")
profiles=json.load(f.read())
f.close()
profiles[id]['display_string']=[display_string]
profiles[id]['profiles']=allprofiles
profiles[id]['name']=currentname
f=open(data_path+"profiles.json","w")
json.dump(profiles,f,indent=4)
f.close()
def update_profile(id,display_string=None,allprofiles=[],name=None):
f=open(data_path+"profiles.json","r")
profiles=json.load(f.read())
f.close()
if id in profiles:
if display_string != None and display_string not in profiles[id]['display_string']:
profiles[id]['display_string'].append(display_string)
if profiles!=[]:
for profile in allprofiles:
if profile not in profiles[id]['profiles']:
profiles[id]['profiles'].append(profile)
if name != None:
profiles[id]['name']=name
f=open(data_path+"profiles.json","w")
json.dump(profiles,f,indent=4)
f.close()
2021-04-10 16:33:19 +05:30
2021-05-31 16:59:13 +05:30
def commit_roles(data):
2021-04-10 16:33:19 +05:30
global roles
if data == {}:
return
2021-05-31 16:59:13 +05:30
output=json.dumps(data,indent=4)
import re
output2 = re.sub(r'": \[\s+', '": [', output)
output3 = re.sub(r'",\s+', '", ', output2)
output4 = re.sub(r'"\s+\]', '"]', output3)
2021-04-10 16:33:19 +05:30
with open(data_path+'roles.json','w') as f:
2021-05-31 16:59:13 +05:30
f.write(output4)
2021-04-10 16:33:19 +05:30
2021-04-07 03:58:40 +05:30
def get_roles():
2021-03-31 13:02:42 +05:30
global roles
2021-04-10 16:33:19 +05:30
if roles == {}:
with open(data_path+'roles.json', 'r') as f:
roles = json.load(f)
2021-03-31 13:02:42 +05:30
return roles
2021-04-10 16:33:19 +05:30
2021-03-31 13:02:42 +05:30
def create_role(role):
global roles
2021-04-10 16:33:19 +05:30
_roles = get_roles()
2021-03-31 13:02:42 +05:30
if role not in _roles:
2021-04-10 16:33:19 +05:30
_roles[role] = {
2021-03-31 13:02:42 +05:30
"tag":role,
2021-04-10 16:33:19 +05:30
"tagcolor":[1,1,1],
2021-03-31 13:02:42 +05:30
"commands":[],
"ids":[]
2021-04-10 16:33:19 +05:30
}
roles = _roles
2021-05-31 16:59:13 +05:30
commit_roles(_roles)
2021-04-10 16:33:19 +05:30
return
return
def add_player_role(role, id):
2021-03-31 13:02:42 +05:30
global roles
2021-04-10 16:33:19 +05:30
_roles = get_roles()
2021-03-31 13:02:42 +05:30
if role in _roles:
2021-05-31 16:59:13 +05:30
2021-04-10 16:33:19 +05:30
if id not in _roles[role]["ids"]:
_roles[role]["ids"].append(id)
roles =_roles
2021-05-31 16:59:13 +05:30
commit_roles(_roles)
else:
print("no role such")
2021-03-31 13:02:42 +05:30
2021-04-10 16:33:19 +05:30
def remove_player_role(role, id):
2021-03-31 13:02:42 +05:30
global roles
2021-04-10 16:33:19 +05:30
_roles = get_roles()
2021-03-31 13:02:42 +05:30
if role in _roles:
2021-04-10 16:33:19 +05:30
_roles[role]["ids"].remove(id)
roles =_roles
2021-05-31 16:59:13 +05:30
commit_roles(_roles)
2021-04-10 16:33:19 +05:30
return "removed from "+role
return "role not exists"
2021-03-31 13:02:42 +05:30
2021-04-10 16:33:19 +05:30
def add_command_role(role, command):
2021-03-31 13:02:42 +05:30
global roles
2021-04-10 16:33:19 +05:30
_roles = get_roles()
2021-03-31 13:02:42 +05:30
if role in _roles:
2021-04-10 16:33:19 +05:30
if command not in _roles[role]["commands"]:
_roles[role]["commands"].append(command)
roles =_roles
2021-05-31 16:59:13 +05:30
commit_roles(_roles)
2021-04-10 16:33:19 +05:30
return "command added to "+role
return "command not exists"
2021-03-31 13:02:42 +05:30
2021-04-10 16:33:19 +05:30
def remove_command_role(role, command):
2021-03-31 13:02:42 +05:30
global roles
2021-04-10 16:33:19 +05:30
_roles = get_roles()
2021-03-31 13:02:42 +05:30
if role in _roles:
2021-04-10 16:33:19 +05:30
if command in _roles[role]["commands"]:
_roles[role]["commands"].remove(command)
roles =_roles
2021-05-31 16:59:13 +05:30
commit_roles(_roles)
2021-04-10 16:33:19 +05:30
return "command added to "+role
return "command not exists"
2021-03-31 13:02:42 +05:30
2021-04-10 16:33:19 +05:30
def change_role_tag(role, tag):
2021-03-31 13:02:42 +05:30
global roles
2021-04-10 16:33:19 +05:30
_roles = get_roles()
2021-03-31 13:02:42 +05:30
if role in _roles:
2021-04-10 16:33:19 +05:30
_roles[role]['tag'] = tag
roles = _roles
2021-05-31 16:59:13 +05:30
commit_roles(_roles)
2021-03-31 13:02:42 +05:30
return "tag changed"
return "role not exists"
2021-05-31 16:59:13 +05:30
def get_player_roles(acc_id):
2021-04-22 14:54:47 +05:30
2021-05-31 16:59:13 +05:30
_roles = get_roles()
roles=[]
2021-04-05 22:13:52 +05:30
for role in _roles:
2021-04-22 14:54:47 +05:30
if acc_id in _roles[role]["ids"]:
2021-05-31 16:59:13 +05:30
roles.append(role)
return roles
2021-04-05 22:13:52 +05:30
2021-04-10 16:33:19 +05:30
##### those ups done will clean it in future
#======================= CUSTOM EFFECTS/TAGS ===============
2021-04-07 03:58:40 +05:30
def get_custom():
global custom
if custom=={}:
2021-04-10 16:33:19 +05:30
with open(data_path+"custom.json","r") as f:
custom = json.loads(f.read())
return custom
2021-04-22 14:54:47 +05:30
return custom
2021-04-10 16:33:19 +05:30
def set_effect(effect, id):
global custom
2021-04-10 16:33:19 +05:30
_custom = get_custom()
_custom['customeffects'][id] = effect
custom = _custom
commit_c()
2021-03-31 13:02:42 +05:30
2021-04-10 16:33:19 +05:30
def set_tag(tag, id):
2021-05-31 16:59:13 +05:30
global custom
2021-04-10 16:33:19 +05:30
_custom = get_custom()
_custom['customtag'][id] = tag
custom = _custom
commit_c()
2021-04-10 16:33:19 +05:30
def remove_effect(id):
global custom
2021-04-10 16:33:19 +05:30
_custom = get_custom()
_custom['customeffects'].pop(id)
2021-04-10 16:33:19 +05:30
custom = _custom
commit_c()
def remove_tag(id):
global custom
2021-04-10 16:33:19 +05:30
_custom = get_custom()
_custom['customtag'].pop(id)
2021-04-10 16:33:19 +05:30
custom = _custom
commit_c()
def commit_c():
global custom
2021-04-10 16:33:19 +05:30
with open(data_path+"custom.json",'w') as f:
json.dump(custom,f,indent=4)
2021-04-22 14:54:47 +05:30
2021-05-31 16:59:13 +05:30
def update_toppers(topperlist):
global roles
_roles = get_roles()
if "top5" not in _roles:
create_role("top5")
roles["top5"]["ids"]=topperlist
commit_roles(roles)