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
|
2021-11-12 09:54:30 +05:30
|
|
|
from serverData import serverdata
|
2021-11-14 17:02:13 +05:30
|
|
|
import time
|
2021-04-10 16:33:19 +05:30
|
|
|
|
|
|
|
|
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-06-26 13:24:49 +05:30
|
|
|
# ============== player data =======================
|
2021-05-31 16:59:13 +05:30
|
|
|
def get_info(id):
|
|
|
|
|
with open(data_path+'profiles.json', 'r') as f:
|
2021-11-10 17:26:07 +05:30
|
|
|
profiles = json.load(f)
|
|
|
|
|
if id in profiles:
|
|
|
|
|
|
|
|
|
|
return profiles[id]
|
|
|
|
|
|
2021-06-26 13:24:49 +05:30
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def get_profiles():
|
|
|
|
|
with open(data_path+'profiles.json', 'r') as f:
|
|
|
|
|
|
|
|
|
|
profiles = json.load(f)
|
|
|
|
|
return profiles
|
|
|
|
|
def commit_profiles(profiles):
|
2021-11-10 17:26:07 +05:30
|
|
|
with open(data_path+'profiles.json', 'w') as f:
|
2021-06-26 13:24:49 +05:30
|
|
|
|
|
|
|
|
json.dump(profiles,f,indent=4)
|
|
|
|
|
|
2021-05-31 16:59:13 +05:30
|
|
|
|
2021-11-12 09:54:30 +05:30
|
|
|
def add_profile(id,display_string,currentname,age):
|
2021-05-31 16:59:13 +05:30
|
|
|
f=open(data_path+"profiles.json","r")
|
2021-11-10 17:26:07 +05:30
|
|
|
profiles=json.load(f)
|
2021-05-31 16:59:13 +05:30
|
|
|
f.close()
|
2021-11-10 17:26:07 +05:30
|
|
|
profiles[id]={"display_string":display_string,
|
|
|
|
|
"profiles":[],
|
|
|
|
|
"name":currentname,
|
|
|
|
|
"isBan":False,
|
|
|
|
|
"isMuted":False,
|
2021-11-12 09:54:30 +05:30
|
|
|
"accountAge":age,
|
2021-11-14 17:02:13 +05:30
|
|
|
"registerOn":time.time(),
|
|
|
|
|
"canStartKickVote":True,
|
2021-11-10 17:26:07 +05:30
|
|
|
"totaltimeplayer":0,
|
|
|
|
|
"lastseen":0}
|
2021-05-31 16:59:13 +05:30
|
|
|
|
2021-11-10 17:26:07 +05:30
|
|
|
|
2021-05-31 16:59:13 +05:30
|
|
|
|
|
|
|
|
f=open(data_path+"profiles.json","w")
|
|
|
|
|
json.dump(profiles,f,indent=4)
|
2021-11-12 09:54:30 +05:30
|
|
|
serverdata.clients[id]=profiles[id]
|
2021-05-31 16:59:13 +05:30
|
|
|
f.close()
|
|
|
|
|
|
2021-11-12 09:54:30 +05:30
|
|
|
def update_displayString(id,display_string):
|
|
|
|
|
profiles=get_profiles()
|
|
|
|
|
if id in profiles:
|
|
|
|
|
profiles[id]["display_string"]=display_string
|
|
|
|
|
commit_profiles(profiles)
|
2021-05-31 16:59:13 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
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-06-26 13:24:49 +05:30
|
|
|
|
|
|
|
|
def ban_player(id):
|
2021-11-10 17:26:07 +05:30
|
|
|
profiles= get_profiles()
|
2021-06-26 13:24:49 +05:30
|
|
|
if id in profiles:
|
|
|
|
|
profiles[id]['isBan']=True
|
|
|
|
|
commit_profiles(profiles)
|
|
|
|
|
|
|
|
|
|
def mute(id):
|
|
|
|
|
profiles=get_profiles()
|
|
|
|
|
if id in profiles:
|
|
|
|
|
|
|
|
|
|
profiles[id]["isMuted"]=True
|
|
|
|
|
commit_profiles(profiles)
|
|
|
|
|
|
|
|
|
|
def unmute(id):
|
|
|
|
|
profiles=get_profiles()
|
|
|
|
|
if id in profiles:
|
|
|
|
|
profiles[id]["isMuted"]=False
|
|
|
|
|
commit_profiles(profiles)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-31 16:59:13 +05:30
|
|
|
|
2021-04-10 16:33:19 +05:30
|
|
|
|
2021-06-26 13:24:49 +05:30
|
|
|
#================ ROLES ==========================
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-02 14:00:25 +05:30
|
|
|
#======================= CUSTOM EFFECTS/TAGS ===============
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 03:58:40 +05:30
|
|
|
def get_custom():
|
2021-04-02 14:00:25 +05:30
|
|
|
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-02 14:00:25 +05:30
|
|
|
|
|
|
|
|
|
2021-04-10 16:33:19 +05:30
|
|
|
def set_effect(effect, id):
|
2021-04-02 14:00:25 +05:30
|
|
|
global custom
|
2021-04-10 16:33:19 +05:30
|
|
|
_custom = get_custom()
|
|
|
|
|
_custom['customeffects'][id] = effect
|
|
|
|
|
custom = _custom
|
2021-04-02 14:00:25 +05:30
|
|
|
commit_c()
|
2021-03-31 13:02:42 +05:30
|
|
|
|
2021-04-02 14:00:25 +05:30
|
|
|
|
2021-04-10 16:33:19 +05:30
|
|
|
def set_tag(tag, id):
|
2021-05-31 16:59:13 +05:30
|
|
|
|
2021-04-02 14:00:25 +05:30
|
|
|
global custom
|
2021-04-10 16:33:19 +05:30
|
|
|
_custom = get_custom()
|
|
|
|
|
_custom['customtag'][id] = tag
|
|
|
|
|
custom = _custom
|
2021-04-02 14:00:25 +05:30
|
|
|
commit_c()
|
|
|
|
|
|
2021-04-10 16:33:19 +05:30
|
|
|
|
2021-04-02 14:00:25 +05:30
|
|
|
def remove_effect(id):
|
|
|
|
|
global custom
|
2021-04-10 16:33:19 +05:30
|
|
|
_custom = get_custom()
|
2021-04-02 14:00:25 +05:30
|
|
|
_custom['customeffects'].pop(id)
|
2021-04-10 16:33:19 +05:30
|
|
|
custom = _custom
|
2021-04-02 14:00:25 +05:30
|
|
|
commit_c()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove_tag(id):
|
|
|
|
|
global custom
|
2021-04-10 16:33:19 +05:30
|
|
|
_custom = get_custom()
|
2021-04-02 14:00:25 +05:30
|
|
|
_custom['customtag'].pop(id)
|
2021-04-10 16:33:19 +05:30
|
|
|
custom = _custom
|
2021-04-02 14:00:25 +05:30
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|