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

170 lines
2.9 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
def commit(data):
global roles
if data == {}:
return
with open(data_path+'roles.json','w') as f:
json.dump(data, f, indent=4)
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
commit(_roles)
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-04-10 16:33:19 +05:30
if id not in _roles[role]["ids"]:
_roles[role]["ids"].append(id)
roles =_roles
commit(_roles)
return "added to "+role
2021-03-31 13:02:42 +05:30
return "role not exists"
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
commit(_roles)
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
commit(_roles)
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
commit(_roles)
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
commit(_roles)
2021-03-31 13:02:42 +05:30
return "tag changed"
return "role not exists"
2021-04-05 22:13:52 +05:30
def get_role(acc_id):
global roles
2021-04-10 16:33:19 +05:30
_roles = get_roles()
2021-04-22 14:54:47 +05:30
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-04-05 22:13:52 +05:30
return role
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):
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
def update_toppers(toperlist):
pass