Bombsquad-Ballistica-Modded.../dist/ba_root/mods/chathandle/handlechat.py

89 lines
3 KiB
Python
Raw Normal View History

2023-08-15 17:37:24 +05:30
# Released under the MIT License. See LICENSE for details.
from datetime import datetime
import setting
2023-08-15 21:59:54 +05:30
from chathandle.chatfilter import chatfilter
from chathandle.chatcommands import command_executor
2023-08-15 17:37:24 +05:30
from features import votingmachine
2023-08-15 21:59:54 +05:30
from playersdata import pdata
from serverdata import serverdata
2023-08-15 17:37:24 +05:30
import bascenev1 as bs
from tools import logger, servercheck
settings = setting.get_settings_data()
def filter_chat_message(msg, client_id):
now = datetime.now()
2025-02-22 21:52:49 +05:30
# bypassing chat filter for host
2023-08-15 17:37:24 +05:30
if client_id == -1:
if msg.startswith("/"):
2023-08-15 21:59:54 +05:30
command_executor.execute(msg, client_id)
2023-08-15 17:37:24 +05:30
return None
logger.log(f"Host msg: | {msg}", "chat")
return msg
acid = ""
displaystring = ""
currentname = ""
for i in bs.get_game_roster():
if i['client_id'] == client_id:
acid = i['account_id']
try:
currentname = i['players'][0]['name_full']
except:
currentname = "<in-lobby>"
displaystring = i['display_string']
if acid:
2023-08-15 21:59:54 +05:30
msg = chatfilter.filter(msg, acid, client_id)
2025-02-22 21:52:49 +05:30
else:
bs.broadcastmessage("Fetching your account info , please wait",
transient=True, clients=[client_id])
return
2023-08-15 17:37:24 +05:30
if msg == None:
return
logger.log(f'{acid} | {displaystring}| {currentname} | {msg}', "chat")
if msg.startswith("/"):
2023-08-15 21:59:54 +05:30
msg = command_executor.execute(msg, client_id)
2023-08-15 17:37:24 +05:30
if msg == None:
return
if msg in ["end", "dv", "nv", "sm"] and settings["allowVotes"]:
votingmachine.vote(acid, client_id, msg)
if acid in serverdata.clients and serverdata.clients[acid]["verified"]:
if serverdata.muted:
bs.broadcastmessage("Server on mute",
transient=True, clients=[client_id])
return
elif acid in pdata.get_blacklist()[
2025-02-22 21:52:49 +05:30
"muted-ids"] and now < datetime.strptime(
pdata.get_blacklist()["muted-ids"][acid]["till"],
"%Y-%m-%d %H:%M:%S"):
2023-08-15 17:37:24 +05:30
bs.broadcastmessage(
"You are on mute, maybe try after some time", transient=True,
clients=[client_id])
return None
elif servercheck.get_account_age(
2025-02-22 21:52:49 +05:30
serverdata.clients[acid]["accountAge"]) < settings[
'minAgeToChatInHours']:
2023-08-15 17:37:24 +05:30
bs.broadcastmessage("New accounts not allowed to chat here",
transient=True, clients=[client_id])
return None
else:
if msg.startswith(",") and settings["allowTeamChat"]:
2023-08-15 21:59:54 +05:30
return command_executor.QuickAccess(msg, client_id)
2023-08-15 17:37:24 +05:30
if msg.startswith(".") and settings["allowInGameChat"]:
2023-08-15 21:59:54 +05:30
return command_executor.QuickAccess(msg, client_id)
2023-08-15 17:37:24 +05:30
return msg
else:
bs.broadcastmessage("Fetching your account info , Wait a minute",
transient=True, clients=[client_id])
return None