efroemling / ballistica

The BombSquad Game Engine
Other
533 stars 106 forks source link

Will there be chat filter? #239

Open schooluser123uheuf opened 3 years ago

schooluser123uheuf commented 3 years ago

Hey I have quick question, will there be a chat filter to censor out offensive words, because there's a lot of players either being racist, sexist or just being bully, one of my friends got called the N-word for no reason and I was called a r****d communist, because it's so dumb when they do stuff like that.

schooluser123uheuf commented 3 years ago

sorry I'm sfill trying to learn properly English

JoseANG3L commented 3 years ago

Hi @schooluser123uheuf . I was working on that chat filter, before it already existed for version 1.4. Created by: Mr. Smoothy 1.4: https://github.com/imayushsaini/Bombsquad-modded-server-Mr.Smoothy/tree/master/chat%20filter

For version 1.5 create it from that mod, this mod saves the bad words they say, the steps to follow are the following: (tested on BombSquad 1.5.29)

Method 1

  1. Open the folder, ba_data / python / ba (Remember to delete the pycache folder for the changes to work)
  2. Replace the _hooks.py file with the new _hooks.py
  3. In the same folder add the file chatWords.py
  4. To add more words, open the file chatWords.py
  5. Done

Method 2

  1. Open the folder, ba_data / python / ba
  2. Replace the _hooks.py file with the new _hooks.py (Remember to delete the pycache folder for the changes to work)
  3. Open the _hooks.py file and search for "filter_chat_message"
  4. Replace that code with the new code Example: Before:

    def filter_chat_message(msg: str, client_id: int) -> Optional[str]:
    """Intercept/filter chat messages.
    
    Called for all chat messages while hosting.
    Messages originating from the host will have clientID -1.
    Should filter and return the string to be displayed, or return None
    to ignore the message.
    """
    del client_id  # Unused by default.
    return msg

    After:

    
    def abusechatsave(msg: str) -> None:
    with open(_ba.env()[
            "python_directory_user"] + "/AbusedChat.txt",mode='a') as f:
        f.write(str(msg+' \n'))
        f.close()

def abusecheck(msg: str) -> None: app = _ba.app

import from mods

# exec('import chatWords')
from ba.chatWords import list1,list2,list3,list4
sp=msg.split()
for f in sp:
    if (f in list1.split()) or (
            f in list2.split()) or (
            f in list3.split()) or (
            f in list4.split(', ')):
        return True
        break
    else:
        pass

def chat(msg: str, client_id: int) -> Optional[str]: if _ba.get_foreground_host_activity() is not None: if abusecheck(msg): if True: abusechatsave(msg)

Ban for 5 minutes.

            # _ba.disconnect_client(client_id, ban_time=5 * 60)

            # Ban for 0 minutes.
            _ba.disconnect_client(client_id, ban_time=0)
            return True
    else:
        return False

def filter_chat_message(msg: str, client_id: int) -> Optional[str]: """Intercept/filter chat messages.

Called for all chat messages while hosting.
Messages originating from the host will have clientID -1.
Should filter and return the string to be displayed, or return None
to ignore the message.
"""
lang = _ba.app.lang.language
if lang == 'Spanish':
    insult = "Por favor no insultes."
    respect = "Respeta."
else:
    insult = "Please don't insult."
    respect = "Respect."
if chat(msg, client_id):
    _ba.screenmessage(
        insult,
        color=(1,0,0),
        clients=[client_id],
        transient=True)
    _ba.screenmessage(
        respect,
        color=(1,0,0),
        clients=[client_id],
        transient=True)
else:
    return msg

5. In the same folder add the file chatWords.py
6. To add more words, open the file chatWords.py
7. Done

_hooks.py:
https://drive.google.com/u/0/uc?id=1EfEB5ESsDYLaS5mhIWLooXwdhOGP2Ybe&export=download

chatWords.py:
https://drive.google.com/u/0/uc?id=1Nd5STFkYPMt04QT152dda_bw7gjX0S6u&export=download