RegEx Chat Filter

Discussion in 'Plugin Requests' started by MPG1, Aug 1, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    MPG1

    Info:
    • Version: 1.14.4 Spigot
    • Category: Chat
    • Suggested Name: RegExChat
    • Due: A.S.A.P i guess
    Thingy:
    You might say there are already RegEx filters out there. I tried some, looked over others, but none fit the bill. I'm looking for the most simple it can get.
    Description:
    If anything matching a regex expression is sent in chat or with configurable commands, it will be replaced with a configurable character.
    Regex expressions will be stored in a text backend, 1 expression per line. (filter.txt)

    Commands:
    Code:
    /regex add <filter> (regex.add):
       Adds a regex expression to the filter list.
    /regex remove <number> (regex.remove):
       Prints a list of filters, click one to remove it. (with toggleable confirm)
    /regex list (regex.list):
       Prints a list of the filters, and the replacement character.
    /regex debug <on/off/print> (regex.debug):
       [on/off] - Toggles debug mode:
       Prints all the messages that matched an expression in a textfile in this format:
          <timestamp> [%user%]:"%text%" - %filter%
       [print] - Prints the textfile of expression matches, but with usernames instead of uuids, 10 per page.
    Other Permissions:
    Code:
    regex.bypass.<filter number>:
    Allows you to bypass the filter indicated.
    regex.bypass.*:
    Allows you to bypass all filters.
    
     
    Last edited: Aug 14, 2020
  2. Offline

    timtower Administrator Administrator Moderator

    @MPG1 Send where? Chat? Or should it also replace messages by plugins?
    Could you post an example file?
     
  3. Offline

    MPG1

    I made edits in italic, for ease of finding.
    Config:
    Code:
    replacechar: "*" # character to replace regex matches
    chatcommands: # commands to filter regex from
    - me
    - w
    - r
    - etc...
    Filters.txt:
    Code:
    d+((\s|_|-)*|.{1,2})(i|1)+((\s|_|-)*|.{1,2})c+((\s|_|-)*|.{1,2})(k|c)+ #example filter for d*ck
    l(a|4)g # example filter for "lag"
    debug.txt (if applicable):
    <timestamp> "lag" - l(a|4)g
     
  4. Offline

    timtower Administrator Administrator Moderator

    @MPG1 checking commands is not easy, or it is just chat or it is with all messages send to the player.
     
  5. Offline

    MPG1

    Yea- the latter.
    Any message sent with a command in the list.
    I think that's a thing in EssentialsXchat, so it should be possible.
     
  6. Offline

    timtower Administrator Administrator Moderator

    @MPG1 EssentialsChat does not handle plugin messages like worldedit, if this is done then it will be done based on packets, not on hooking into specific plugins.
     
  7. Offline

    KarimAKL

    @MPG1 I haven't tried this with other plugins so, i'm not sure how compatible it is.

    Anyway, try this.

    Note: I'm not done, i just wanted to give you a "preview" file. The replacing as well as the "/regex add (some filter here)" command should already be working, it's just the other 3 commands. I also wanted to add a parameter of sorts to the config so it can be like "- tell 2,3" or something. I'm thinking those will be used to exclude arguments from the commands so you won't censor the player's name when trying to send them a message.

    Let me know what you think about the idea and the "preview" plugin.
     
  8. Offline

    MPG1

    Thanks! I will try this A.S.A.P, and I am really thankful for this. Hooray!

    Edit: Woah! I love the help command, the config and the backend. This is AWESOME! (Please continue)
     
    Last edited: Aug 6, 2020
    KarimAKL likes this.
  9. Offline

    MPG1

    bump for KarimAKL
     
    KarimAKL likes this.
  10. Offline

    KarimAKL

    Glad to hear it. :) I'm currently not at my PC but, i will be back this Sunday.
     
  11. Offline

    KarimAKL

    @MPG1 Update: I've added the ability to exclude certain arguments from being censored as mentioned above. I'm now implementing the rest of the commands.

    Edit: I believe everything should be working now, let me know if you have any problems or questions, i'll be happy to answer them.

    Download: https://www.dropbox.com/s/2a8v3kd5krop1bk/RegExChat.jar?dl=0

    I changed a few things for the logging as well to display the sender of the message. (The command will only display their name while the files will display their name along with their UUID)
     
    Last edited by a moderator: Aug 10, 2020
    MPG1 likes this.
  12. Offline

    MPG1

    Will try ASAP. Was out for last 4 days sorry. :p

    Edit: WOW it works really nicely. 1 thing though- The numerical indexes don't show up when you type "/regex list", and it seems you can't remove filters based on index. I like what you added for the debug, and i really thank you for building this for me. Also, have you finished the permissions?

    Bump! @KarimAKL

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 13, 2020
    KarimAKL likes this.
  13. Offline

    KarimAKL

    You never explained those, how are they supposed to work?

    Now that you mention it, i believe i forgot to check the bypass permission. I'll add that after your answer to the above question.
     
  14. Offline

    MPG1

    /regex list:
    Another thing, is there a way to disable the debug with ingame commads? I will update the first post with details.

    Edit: Update done. Check debug command, sorry I wasn't clear before.
     
    Last edited: Aug 14, 2020
  15. Offline

    KarimAKL

    @MPG1 But how is the filters supposed to be numbered? Is it by the line index in the file? Also, do you want to still be able to print the logs while debug is off?

    Btw, i'll be back at my PC tomorrow, i can make these changes then.
     
  16. Offline

    MPG1

    Yes, I suppose. Based on the order in which they were added.
    That would be nice.
    Thanks Thanks Thanks :)
     
  17. Offline

    KarimAKL

  18. Offline

    MPG1

    I love how it looks! The debug works, but there are a couple tings:
    1. When printing the filter list, the first index is 0, instead of 1. To remove filter "0", you have to run /regex remove 1 I would like it if the first filter showed up as "1".
    2. There doesn't seem to be a "regex.bypass" permission. I was wrong- nvm
    Thanks for helping me all this way, I really thank you. :) :) :)
     
    Last edited: Aug 17, 2020
    KarimAKL likes this.
  19. Offline

    KarimAKL

    That was my intention, i guess i forgot to add 1. I'll have a look at the code.

    Edit: After 15 hard working minutes of opening my IDE and compiling the plugin, i've managed to add 1 to the numbers in the list.

    Download: https://www.dropbox.com/s/2a8v3kd5krop1bk/RegExChat.jar?dl=0

    Anyway, i also fixed a mistake on my part that made it so you wouldn't get a "You removed this filter" message if you were removing it by index instead of by regex.
     
    Last edited by a moderator: Aug 17, 2020
    MPG1 likes this.
  20. Offline

    MPG1

    Trying ASAP.

    Edit: It works great! There is just 1 thing I would like- My current replacement character contains color codes. People without permissions for color codes end up just saying the raw text. Is there some way to fix this? If not, that's ok.
     
    Last edited: Aug 18, 2020
  21. Offline

    MPG1

    hah 24 hours and 8 minutes bump
     
  22. Offline

    KarimAKL

    The color code character is '§'. '&' is simply replaced with '§' in plugins because that character has been accepted as the default and we can't type '§' in Minecraft.

    So if players have the permission for color codes, the text will look like "§3Red text here", if not, it'll be "&3Red text here".

    Anyway, if this didn't help in any way, could you elaborate on what you want to do so that i might understand the problem better?
     
  23. Offline

    MPG1

    Ok. The replacement character is "&4&k-&r". For someone with "luckpermschat.chatcolors"(color chat perm), it looks like a dark red obfuscated dash (correct). For someone without the color chat permission, the replacement character is sent- literally- like this: "[Noob] Steve: &4&k-&r&4&k-&r&4&k-&r". Is there a way you could fix this?
     
  24. Offline

    KarimAKL

    @MPG1 Does this fix the issue? What i did was simply replacing '&' in the replacement string to '§'. That's what i was trying to help you with before.
     
  25. Offline

    MPG1

    Ah, sorry it was a little unclear. I will get back to you ASAP about this.
     
  26. Offline

    MPG1

    oook. sorry it's taking so long, thanks, i will let you know if it still doesn't work,
     
Thread Status:
Not open for further replies.

Share This Page