basic role management and chatcmd

This commit is contained in:
Ayush Saini 2021-03-31 13:02:42 +05:30
parent 0fd45fb29e
commit 826f433e38
15 changed files with 236 additions and 1 deletions

View file

@ -0,0 +1,44 @@
# Released under the MIT License. See LICENSE for details.
import ba
import _ba
from playersData import pdata
import fun,management
import setting
def public_id(client_id):
rost=_ba.get_game_roster()
for client in rost:
if client['client_id']==client_id:
return client['account_id']
return None
def check_permission(pbid,cmnd):
roles=pdata.roles()
for role in roles:
if pbid in role.ids and cmnd in role.commands:
return True
return False
def cmd_type(cmnd):
if cmnd in fun.cmnds:
return "fun"
if cmnd in management.cmnds:
return "management"
def cmd(msg,client_id):
cmnd=msg.split(" ")[0].lower()
arg=msg.split(" ")[1:]
pbid=public_id(client_id)
if check_permission(pbid,cmnd):
if cmd_type(cmnd)=="fun":
fun.exec_cmd(cmnd,arg,client_id,pbid)
elif cmd_type(cmnd)=="management":
management.exec_cmd(cmnd,arg,client_id,pbid)
else:
_ba.chatmessage("no access",clients=client_id)
if setting.brdcast_chatcmd:
return msg
return None

View file

@ -0,0 +1,23 @@
# Released under the MIT License. See LICENSE for details.
cmnds=["/fly","/freeze"]
def exec_cmd(cmnd,arg,client_id,pbid):
if cmnd =="/fly":
fly()
# ==============
def fly():
# do something
def freeze():
# do something
def spaz():
#do something

View file

@ -0,0 +1,22 @@
# Released under the MIT License. See LICENSE for details.
cmnds=["/add","/kick"]
def exec_cmd(cmnd,arg,client_id,pbid):
if cmnd =="/kick":
kick(arg[0])
# ==============
def kick(client_id):
_ba.disconnectclient(client_id)
# do something
def add():
# do something
def end():
#do something

View file

@ -0,0 +1,3 @@
# Released under the MIT License. See LICENSE for details.
def isAbuse():
return

View file

@ -1,2 +1,24 @@
import playersData
# Released under the MIT License. See LICENSE for details.
from playersData import pdata
from chatCMDS import chatcmd
from chatFilter import chatfilter
import ba,_ba
def public_id(client_id):
rost=_ba.get_game_roster()
for client in rost:
if client['client_id']==client_id:
return client['account_id']
return None
def filter_chat_message(msg,client_id):
if msg.startswith("/"):
return chatcmd.cmd(msg,client_id)
if chatfilter.isAbuse(msg):
pdata.warn(public_id(client_id))
return None
return msg

89
dist/ba_root/mods/playersData/pdata.py vendored Normal file
View file

@ -0,0 +1,89 @@
# Released under the MIT License. See LICENSE for details.
roles={}
data={}
def roles():
global roles
if roles=={}:
f=open("roles.json","r")
dat=json.loads(f.read())
roles=dat
f.close()
return roles
def create_role(role):
global roles
_roles=roles()
if role not in _roles:
_roles[role]={
"tag":role,
"tagcolor":(1,1,1),
"commands":[],
"ids":[]
}
roles=_roles
comit()
return 'created successfully'
return 'already exists'
def add_player_role(role,id):
global roles
_roles=roles()
if role in _roles:
_roles[role].ids.append(id)
roles=_roles
commit()
return 'added to '+role
return "role not exists"
def add_command_role(role,command):
global roles
_roles=roles()
if role in _roles:
_roles[role].commands.append(command)
roles=_roles
commit()
return 'added '+command+"to "+role
return role+"not exists"
def remove_player_role(role,id):
global roles
_roles=roles()
if role in _roles:
_roles[role].ids.remove(id)
roles=_roles
commit()
return "removed"
return "role not exists"
def remove_command_role():
global roles
_roles=roles()
if role in _roles:
_roles[role].commands.remove(command)
roles=_roles
commit()
return 'removed '+command+"from "+role
return role+"not exists"
def change_role_tag(role,tag):
global roles
_roles=roles()
if role in _roles:
_roles[role].tag=tag
roles=_roles
commit()
return "tag changed"
return "role not exists"
def commit():
global roles
f=open("roles.json",'w')
json.dump(roles,f,indent=4)
f.close()

View file

@ -0,0 +1,27 @@
{
"owner":{
"tag":"OWNER",
"tagcolor":(1,1,1),
"commands":["add","kick","remove"],
"ids":["pb-ihugg7g9==","pb-7gt78"]
},
"admin":{
"tag":"ADMIN",
"tagcolor":(1,1,1),
"commands":["kick","end"],
"ids":["pb-ugg","pb-767fyfd"]
},
"vip":{
"tag":"VIP",
"tagcolor":(1,1,1),
"commands":[],
"ids":[]
},
"donor":{
"tag":"DONOR",
"tagcolor":(2,2,2),
"commands":[],
"ids":[]
}
}

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1 @@
# Released under the MIT License. See LICENSE for details.

View file

@ -0,0 +1 @@
# Released under the MIT License. See LICENSE for details.

View file

@ -0,0 +1 @@
# Released under the MIT License. See LICENSE for details.

Binary file not shown.

View file

@ -0,0 +1 @@
# Released under the MIT License. See LICENSE for details.

View file

@ -0,0 +1 @@
# Released under the MIT License. See LICENSE for details.