From ae35ad7055f1ac1faf1aff086d095aa369b6d391 Mon Sep 17 00:00:00 2001 From: Freaku17 <92618708+Freaku17@users.noreply.github.com> Date: Sat, 2 Apr 2022 13:58:32 +0530 Subject: [PATCH 1/2] Add files via upload --- .../mods/chatHandle/chatFilter/ChatFilter.py | 179 ++++++++++-------- 1 file changed, 100 insertions(+), 79 deletions(-) diff --git a/dist/ba_root/mods/chatHandle/chatFilter/ChatFilter.py b/dist/ba_root/mods/chatHandle/chatFilter/ChatFilter.py index 0fdddee..d84d700 100644 --- a/dist/ba_root/mods/chatHandle/chatFilter/ChatFilter.py +++ b/dist/ba_root/mods/chatHandle/chatFilter/ChatFilter.py @@ -1,79 +1,100 @@ -# Released under the MIT License. See LICENSE for details. -import ba, _ba -from serverData import serverdata -from features import profanity -from tools import servercheck -import time -import setting -from tools import logger -import _thread -settings = setting.get_settings_data() - - -def filter(msg,pb_id,client_id): - new_msg=profanity.censor(msg) - if new_msg!=msg: - addWarn(pb_id,client_id) - - now = time.time() - if pb_id not in serverdata.clients: - return None - - if "lastMsgTime" in serverdata.clients[pb_id]: - count=serverdata.clients[pb_id]["cMsgCount"] - smsgcount=serverdata.clients[pb_id]['cSameMsg'] - if now - serverdata.clients[pb_id]["lastMsgTime"] < 5: - count+=1 - if count >=2: - addWarn(pb_id,client_id) - count =0 - elif now - serverdata.clients[pb_id]["lastMsgTime"] < 30: - if serverdata.clients[pb_id]["lastMsg"]==msg: - if len(msg)>5: - smsgcount+=1 - if smsgcount>=3: - logger.log(pb_id+" | kicked for chat spam") - _ba.disconnect_client(client_id) - smsgcount=0 - addWarn(pb_id,client_id) - else: - smsgcount=0 - else: - count =0 - smsgcount=0 - - - serverdata.clients[pb_id]['cMsgCount']=count - serverdata.clients[pb_id]['lastMsgTime']=now - serverdata.clients[pb_id]['lastMsg']=msg - serverdata.clients[pb_id]['cSameMsg']=smsgcount - else: - serverdata.clients[pb_id]['cMsgCount']=0 - serverdata.clients[pb_id]['lastMsgTime']=now - serverdata.clients[pb_id]['lastMsg']=msg - serverdata.clients[pb_id]['cSameMsg']=0 - return new_msg - - - -def addWarn(pb_id,client_id): - now=time.time() - player=serverdata.clients[pb_id] - warn=player['warnCount'] - if now - player['lastWarned'] <= settings["WarnCooldownMinutes"]*60: - warn+=1 - if warn > settings["maxWarnCount"]: - _ba.screenmessage(settings["afterWarnKickMsg"],color=(1,0,0),transient=True,clients=[client_id]) - logger.log(pb_id+" | kicked for chat spam") - _ba.disconnect_client(client_id) - _thread.start_new_thread(servercheck.reportSpam,(pb_id,)) - - else: - _ba.screenmessage(settings["warnMsg"],color=(1,0,0),transient=True,clients=[client_id]) - else: - warn=0 - serverdata.clients[pb_id]["warnCount"]=warn - serverdata.clients[pb_id]['lastWarned']=now - - - +# Released under the MIT License. See LICENSE for details. +import ba, _ba +from serverData import serverdata +from features import profanity +from tools import servercheck +import time +import setting +from tools import logger +import _thread +from playersData import pdata +settings = setting.get_settings_data() + +def check_permissions(accountid): + roles = pdata.get_roles() + for role in roles: + if accountid in roles[role]["ids"] and "ALL" in roles[role]["commands"]: + return True + return False + + +def filter(msg,pb_id,client_id): + new_msg=profanity.censor(msg) + if new_msg!=msg: + _ba.screenmessage("Don\'t ABUSE!", color=(1,0,0), transient=True, clients=[client_id]) + if not check_permissions(pb_id): + addWarn(pb_id,client_id) + else: + _ba.screenmessage("Special role found, Warn BYPASSED!", color=(0,1,0), transient=True, clients=[client_id]) + + now = time.time() + + if "lastMsgTime" in serverdata.clients[pb_id]: + count=serverdata.clients[pb_id]["cMsgCount"] + smsgcount=serverdata.clients[pb_id]['cSameMsg'] + if now - serverdata.clients[pb_id]["lastMsgTime"] < 8: + count+=1 + if count == 2: #when 3 msgs + _ba.screenmessage("Sending messages too fast, cool down...", color=(1,0.40,0.50), transient=True, clients=[client_id]) + elif count >=3: #when 4 msgs + _ba.screenmessage("Don\'t SPAM!", color=(1,0,0), transient=True, clients=[client_id]) + if not check_permissions(pb_id): + addWarn(pb_id,client_id) + else: + _ba.screenmessage("Special role found, Warn BYPASSED!", color=(0,1,0), transient=True, clients=[client_id]) + count =0 + elif now - serverdata.clients[pb_id]["lastMsgTime"] < 20: +# < 30 + if serverdata.clients[pb_id]["lastMsg"]==msg: + if len(msg)>5: + smsgcount+=1 + if smsgcount>=3: + logger.log(pb_id+" | kicked for chat spam") + _ba.disconnect_client(client_id) + smsgcount=0 + _ba.screenmessage("Don\'t SPAM!", color=(1,0,0), transient=True, clients=[client_id]) + if not check_permissions(pb_id): + addWarn(pb_id,client_id) + else: + _ba.screenmessage("Special role found, Warn BYPASSED!", color=(0,1,0), transient=True, clients=[client_id]) + else: + smsgcount=0 + else: + count =0 + smsgcount=0 + + + serverdata.clients[pb_id]['cMsgCount']=count + serverdata.clients[pb_id]['lastMsgTime']=now + serverdata.clients[pb_id]['lastMsg']=msg + serverdata.clients[pb_id]['cSameMsg']=smsgcount + else: + serverdata.clients[pb_id]['cMsgCount']=0 + serverdata.clients[pb_id]['lastMsgTime']=now + serverdata.clients[pb_id]['lastMsg']=msg + serverdata.clients[pb_id]['cSameMsg']=0 + return new_msg + + + +def addWarn(pb_id,client_id): + now=time.time() + player=serverdata.clients[pb_id] + warn=player['warnCount'] + if now - player['lastWarned'] <= settings["WarnCooldownMinutes"]*60: + warn+=1 + if warn > settings["maxWarnCount"]: + _ba.screenmessage(settings["afterWarnKickMsg"],color=(1,0,0),transient=True,clients=[client_id]) + logger.log(pb_id+" | kicked for chat spam") + _ba.disconnect_client(client_id) + _thread.start_new_thread(servercheck.reportSpam,(pb_id,)) + + else: + _ba.screenmessage(settings["warnMsg"]+f"\n\nWarn Count = {warn}/3!!!",color=(1,0,0),transient=True,clients=[client_id]) + else: + warn=0 + serverdata.clients[pb_id]["warnCount"]=warn + serverdata.clients[pb_id]['lastWarned']=now + + + From 6d4dc3a630c24717591fb71b061979e5aaf42c91 Mon Sep 17 00:00:00 2001 From: Ayush Saini <36878972+imayushsaini@users.noreply.github.com> Date: Sat, 2 Apr 2022 14:26:14 +0530 Subject: [PATCH 2/2] bypass for owner and special role --- dist/ba_root/mods/chatHandle/chatFilter/ChatFilter.py | 2 +- dist/ba_root/mods/playersData/roles.json | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dist/ba_root/mods/chatHandle/chatFilter/ChatFilter.py b/dist/ba_root/mods/chatHandle/chatFilter/ChatFilter.py index d84d700..f456838 100644 --- a/dist/ba_root/mods/chatHandle/chatFilter/ChatFilter.py +++ b/dist/ba_root/mods/chatHandle/chatFilter/ChatFilter.py @@ -13,7 +13,7 @@ settings = setting.get_settings_data() def check_permissions(accountid): roles = pdata.get_roles() for role in roles: - if accountid in roles[role]["ids"] and "ALL" in roles[role]["commands"]: + if accountid in roles[role]["ids"] and ( role == "bypass-warn" or role=="owner") : return True return False diff --git a/dist/ba_root/mods/playersData/roles.json b/dist/ba_root/mods/playersData/roles.json index 29fc633..335ea7c 100644 --- a/dist/ba_root/mods/playersData/roles.json +++ b/dist/ba_root/mods/playersData/roles.json @@ -46,5 +46,13 @@ ], "commands": [], "ids": ["pb-IF5XUm9eAg==", "pb-IF43VUwlAg==", "pb-IF4iVUc5Cg==", "pb-IF4vNnMJ", "pb-IF4TVWwZUQ=="] + }, + "bypass-warn": { + "tag": "", "tagcolor": [1, + 1, + 1 + ], + "commands": [], + "ids": ["pb-IF5XUm9eAg==", "pb-IF43VUwlAg==", "pb-IF4iVUc5Cg==", "pb-IF4vNnMJ", "pb-IF4TVWwZUQ=="] } } \ No newline at end of file