vh-bombsquad-modded-server-.../dist/ba_root/mods/chatHandle/ChatCommands/Main.py

264 lines
12 KiB
Python
Raw Normal View History

2024-02-26 00:17:10 +05:30
# Released under the MIT License. See LICENSE for details.
2024-04-21 00:18:53 +05:30
2024-02-26 00:17:10 +05:30
from .commands import NormalCommands
from .commands import Management
from .commands import Fun
from .commands import Cheats
from .commands import NewCmds
from .commands import CoinCmds
2024-04-07 05:18:18 +05:30
from chatHandle.ChatCommands.commands import NormalCommands as nc
from chatHandle.ChatCommands.commands import CoinCmds as cc
from chatHandle.ChatCommands.commands.Handlers import send, sendall
2024-02-26 00:17:10 +05:30
from .Handlers import clientid_to_accountid
from .Handlers import check_permissions
from chatHandle.chatFilter import ChatFilter
from bastd.actor import popuptext
import ba
import _ba
import ba.internal
2024-04-07 05:18:18 +05:30
import set
2024-02-26 00:17:10 +05:30
import setting
from datetime import datetime
from playersData import pdata
from serverData import serverdata
settings = setting.get_settings_data()
2024-04-07 05:18:18 +05:30
tic = settings["CurrencyType"]["Currency"]
2024-02-26 00:17:10 +05:30
def return_role(accountid):
roles = pdata.get_roles()
for role in roles:
if accountid in roles[role]["ids"]:
return role
return False
def command_type(command):
"""
Checks The Command Type
Parameters:
command : str
Returns:
any
"""
if command in NormalCommands.Commands or command in NormalCommands.CommandAliases:
return "Normal"
if command in Management.Commands or command in Management.CommandAliases:
return "Manage"
if command in Fun.Commands or command in Fun.CommandAliases:
return "Fun"
if command in Cheats.Commands or command in Cheats.CommandAliases:
return "Cheats"
if command in NewCmds.Commands or command in NewCmds.CommandAliases:
return "NewCmd"
if command in CoinCmds.Commands or command in CoinCmds.CommandAliases:
return "CoinCmd"
def Command(msg, clientid):
command = msg.lower().split(" ")[0].split("/")[1]
arguments = msg.lower().split(" ")[1:]
accountid = clientid_to_accountid(clientid)
2024-03-31 13:34:28 +05:30
ARGUMENTS = msg.upper().split(" ")[1:]
2024-02-26 00:17:10 +05:30
role = return_role(accountid)
if role == 'owner':
reply = '\ue049|| \ue00cCOMMAND ACCEPTED OWNER\ue00c ||\ue049'
elif role == 'admin':
reply = '\ue049|| \ue00cCOMMAND ACCEPTED ADMIN\ue00c ||\ue049'
elif role == 'vip':
reply = '\ue049|| \ue00cCOMMAND ACCEPTED VIP\ue00c ||\ue049'
2024-04-07 05:18:18 +05:30
elif role in ['moderator', 'mods', 'mod']:
2024-02-26 00:17:10 +05:30
reply = '\ue049|| \ue00cCOMMAND ACCEPTED MODERATOR\ue00c ||\ue049'
2024-04-07 05:18:18 +05:30
elif role in ['leadstaff', 'lead-staff', 'leads']:
2024-02-26 00:17:10 +05:30
reply = '\ue049|| \ue00cCOMMAND ACCEPTED LEAD-STAFF\ue00c ||\ue049'
2024-04-07 05:18:18 +05:30
elif role in ['staff', 'cs', 'complaintstaff', 'complaint-staff']:
2024-04-21 00:18:53 +05:30
reply = '\ue049|| \ue00cCOMMAND ACCEPTED STAFF\ue00c ||\ue049'
2024-02-26 00:17:10 +05:30
else:
2024-04-07 05:18:18 +05:30
reply = None
2024-02-26 00:17:10 +05:30
if command_type(command) == "Normal":
2024-03-31 13:34:28 +05:30
NormalCommands.ExcelCommand(command, arguments, clientid, accountid, ARGUMENTS)
2024-02-26 00:17:10 +05:30
elif command_type(command) == "CoinCmd":
CoinCmds.CoinCommands(command, arguments, clientid, accountid)
2024-03-31 13:34:28 +05:30
2024-02-26 00:17:10 +05:30
elif command_type(command) == "Manage":
if check_permissions(accountid, command):
Management.ExcelCommand(command, arguments, clientid, accountid)
2024-04-07 05:18:18 +05:30
if reply is not None:
_ba.screenmessage(reply, color=(0,1,0), transient=True)
2024-02-26 00:17:10 +05:30
else:
2024-04-21 00:18:53 +05:30
if settings.get("paidCommands", False):
if command in set.availablecommands:
cost_of_command = set.availablecommands[command]
have_coins = nc.getcoins(accountid)
if have_coins >= cost_of_command:
Management.ExcelCommand(command, arguments, clientid, accountid)
cc.addcoins(accountid, cost_of_command * -1)
sendall(f"Success! /{command} cost you {tic}{cost_of_command}.")
else:
send(f"You need {tic}{cost_of_command} for that. You have {tic}{have_coins} only.", clientid)
2024-04-07 05:18:18 +05:30
else:
2024-04-21 00:18:53 +05:30
_ba.screenmessage(u"\ue049|| \ue00cCOMMAND NOT FOR KIDS\ue00c ||\ue049", color=(1, 0, 0), transient=True,
clients=[clientid])
2024-04-07 05:18:18 +05:30
else:
_ba.screenmessage(u"\ue049|| \ue00cCOMMAND NOT FOR KIDS\ue00c ||\ue049", color=(1, 0, 0), transient=True,
2024-02-26 00:17:10 +05:30
clients=[clientid])
elif command_type(command) == "Fun":
if check_permissions(accountid, command):
Fun.ExcelCommand(command, arguments, clientid, accountid)
2024-04-07 05:18:18 +05:30
if reply is not None:
_ba.screenmessage(reply, color=(0,1,0), transient=True)
2024-02-26 00:17:10 +05:30
else:
2024-04-21 00:18:53 +05:30
if settings.get("paidCommands", False):
if command in set.availablecommands:
cost_of_command = set.availablecommands[command]
have_coins = nc.getcoins(accountid)
if have_coins >= cost_of_command:
Fun.ExcelCommand(command, arguments, clientid, accountid)
cc.addcoins(accountid, cost_of_command * -1)
sendall(f"Success! /{command} cost you {tic}{cost_of_command}.")
else:
send(f"You need {tic}{cost_of_command} for that. You have {tic}{have_coins} only.", clientid)
2024-04-07 05:18:18 +05:30
else:
2024-04-21 00:18:53 +05:30
_ba.screenmessage(u"\ue049|| \ue00cCOMMAND NOT FOR KIDS\ue00c ||\ue049", color=(1, 0, 0), transient=True,
clients=[clientid])
2024-04-07 05:18:18 +05:30
else:
_ba.screenmessage(u"\ue049|| \ue00cCOMMAND NOT FOR KIDS\ue00c ||\ue049", color=(1, 0, 0), transient=True,
2024-02-26 00:17:10 +05:30
clients=[clientid])
elif command_type(command) == "Cheats":
if check_permissions(accountid, command):
Cheats.ExcelCommand(command, arguments, clientid, accountid)
2024-04-07 05:18:18 +05:30
if reply is not None:
_ba.screenmessage(reply, color=(0,1,0), transient=True)
2024-02-26 00:17:10 +05:30
else:
2024-04-21 00:18:53 +05:30
if settings.get("paidCommands", False):
if command in set.availablecommands:
cost_of_command = set.availablecommands[command]
have_coins = nc.getcoins(accountid)
if have_coins >= cost_of_command:
Cheats.ExcelCommand(command, arguments, clientid, accountid)
cc.addcoins(accountid, cost_of_command * -1)
sendall(f"Success! /{command} cost you {tic}{cost_of_command}.")
else:
send(f"You need {tic}{cost_of_command} for that. You have {tic}{have_coins} only.", clientid)
2024-04-07 05:18:18 +05:30
else:
2024-04-21 00:18:53 +05:30
_ba.screenmessage(u"\ue049|| \ue00cCOMMAND NOT FOR KIDS\ue00c ||\ue049", color=(1, 0, 0), transient=True,
clients=[clientid])
2024-04-07 05:18:18 +05:30
else:
_ba.screenmessage(u"\ue049|| \ue00cCOMMAND NOT FOR KIDS\ue00c ||\ue049", color=(1, 0, 0), transient=True,
2024-02-26 00:17:10 +05:30
clients=[clientid])
elif command_type(command) == "NewCmd":
if check_permissions(accountid, command):
2024-02-29 09:49:51 +05:30
NewCmds.NewCommands(command, arguments, clientid, accountid)
2024-04-07 05:18:18 +05:30
if reply is not None:
_ba.screenmessage(reply, color=(0,1,0), transient=True)
2024-02-26 00:17:10 +05:30
else:
2024-04-21 00:18:53 +05:30
if settings.get("paidCommands", False):
if command in set.availablecommands:
cost_of_command = set.availablecommands[command]
have_coins = nc.getcoins(accountid)
if have_coins >= cost_of_command:
NewCmds.NewCommands(command, arguments, clientid, accountid)
cc.addcoins(accountid, cost_of_command * -1)
sendall(f"Success! /{command} cost you {tic}{cost_of_command}.")
else:
send(f"You need {tic}{cost_of_command} for that. You have {tic}{have_coins} only.", clientid)
2024-04-07 05:18:18 +05:30
else:
2024-04-21 00:18:53 +05:30
_ba.screenmessage(u"\ue049|| \ue00cCOMMAND NOT FOR KIDS\ue00c ||\ue049", color=(1, 0, 0), transient=True,
clients=[clientid])
2024-04-07 05:18:18 +05:30
else:
_ba.screenmessage(u"\ue049|| \ue00cCOMMAND NOT FOR KIDS\ue00c ||\ue049", color=(1, 0, 0), transient=True,
2024-04-21 00:18:53 +05:30
clients=[clientid])
2024-02-26 00:17:10 +05:30
now = datetime.now()
if accountid in pdata.get_blacklist()["muted-ids"] and now < datetime.strptime(pdata.get_blacklist()["muted-ids"][accountid]["till"], "%Y-%m-%d %H:%M:%S"):
2024-04-21 00:18:53 +05:30
_ba.screenmessage(f"You are on mute", transient=True,
2024-02-26 00:17:10 +05:30
clients=[clientid])
return None
2024-03-31 13:34:28 +05:30
2024-02-26 00:17:10 +05:30
if serverdata.muted:
return None
2024-03-31 13:34:28 +05:30
prefixes = settings["CmdChatDisable"]["Commands"]
if any(msg.startswith(f"/{prefix}") for prefix in prefixes) and settings["CmdChatDisable"]["disable"]:
return None
2024-04-07 05:18:18 +05:30
elif msg.startswith("/comp") or msg.startswith("/complaint") and not settings["compChatText"]:
2024-03-31 13:34:28 +05:30
return None # Disable the "/comp" command if compChatText setting is False
elif settings["ChatCommands"]["BrodcastCommand"]:
2024-02-26 00:17:10 +05:30
return msg
return None
def QuickAccess(msg, client_id):
if msg.startswith(","):
name = ""
teamid = 0
for i in ba.internal.get_foreground_host_session().sessionplayers:
if i.inputdevice.client_id == client_id:
teamid = i.sessionteam.id
name = i.getname(True)
for i in ba.internal.get_foreground_host_session().sessionplayers:
if hasattr(i, 'sessionteam') and i.sessionteam and teamid == i.sessionteam.id and i.inputdevice.client_id != client_id:
_ba.screenmessage(name + ":" + msg[1:], clients=[i.inputdevice.client_id],
color=(0.3, 0.6, 0.3), transient=True)
return None
2024-03-31 13:34:28 +05:30
elif msg.startswith("/dm"):
2024-04-28 17:01:30 +05:30
a = msg.split()[1:]
2024-03-31 13:34:28 +05:30
if len(a) < 2: # Check if there are enough arguments
send(f"Usage: /dm [clientid] [message]", client_id)
else:
2024-04-28 17:01:30 +05:30
clientid = int(a[0])
message = ' '.join(a[1:]) # Join the message list into a single string
2024-03-31 13:34:28 +05:30
for me in ba.internal.get_game_roster():
if me["client_id"] == client_id:
2024-04-28 17:01:30 +05:30
pname = me["display_string"]
#=============================================================================================
for me in ba.internal.get_game_roster():
2024-03-31 13:34:28 +05:30
if me["client_id"] == clientid:
name = me["display_string"]
break
2024-04-28 17:01:30 +05:30
if name:
2024-03-31 13:34:28 +05:30
try:
send(f"{pname}: {message}", clientid)
send(f"DM sent successfully to {name}", client_id)
except Exception as e:
print(f"Failed to send DM to {name}: {e}")
send(f"Failed to send DM to {name}.", client_id)
else:
send(f"Player not found with client ID {clientid}.", client_id)
#-----------------------------------------------------------------------------------
2024-02-26 00:17:10 +05:30
elif msg.startswith("."):
msg = msg[1:]
msgAr = msg.split(" ")
if len(msg) > 25 or int(len(msg) / 5) > len(msgAr):
_ba.screenmessage("msg/word length too long",
clients=[client_id], transient=True)
return None
msgAr.insert(int(len(msgAr) / 2), "\n")
for player in _ba.get_foreground_host_activity().players:
if player.sessionplayer.inputdevice.client_id == client_id and player.actor.exists() and hasattr(player.actor.node, "position"):
pos = player.actor.node.position
with _ba.Context(_ba.get_foreground_host_activity()):
popuptext.PopupText(
" ".join(msgAr), (pos[0], pos[1] + 1, pos[2])).autoretain()
return None
return None