Declipsonator / Chat-Control

Take back control of your server chat with filters and mutes. (Star? 🥺)
Other
3 stars 0 forks source link

RegEx doesn't seem to work properly or maybe at all & replacementLetters command seems unusable #1

Closed MrRubberDucky closed 2 years ago

MrRubberDucky commented 2 years ago

Well I tried to add a regex in many ways, adding ", yeeting ()'s, removing []'s and so on and so on and yet the result is always the same.

Here's a example regex I made that targets words bsss and baas while also being case insensitive: (?i)b(?:aa|ss)s$ Expected result would be for Chat Control to filter the message if a match happens but instead it still lets the message through as if the regex does nothing, yet when validating in another self-made java application or some online site, the regex works perfectly. The command /filter add regex also accepts anything, even total garbage and doesn't validate the input so I can just do /filter add regex asfdsfjdsf and it will save it in and say it was added successfully.

Not sure if related but here are some errors, not sure why but maybe it is because I have some letters with numbers in them, once again there's no input validation to really tell you that you shouldn't put numbers in there so for someone that doesn't know it might actually confuse someone

[13:13:40] [Netty Server IO #2/ERROR]: Could not serialize me.declipsonator.chatcontrol.util.CharArgumentType@4b272c98 (class me.declipsonator.chatcontrol.util.CharArgumentType) - will not be sent to client!
[13:13:40] [Netty Server IO #2/ERROR]: Could not serialize me.declipsonator.chatcontrol.util.CharArgumentType@2ad5805f (class me.declipsonator.chatcontrol.util.CharArgumentType) - will not be sent to client!
[13:13:40] [Netty Server IO #2/ERROR]: Could not serialize me.declipsonator.chatcontrol.util.CharArgumentType@312c614d (class me.declipsonator.chatcontrol.util.CharArgumentType) - will not be sent to client!
[13:13:40] [Netty Server IO #2/ERROR]: Could not serialize me.declipsonator.chatcontrol.util.CharArgumentType@4a8f24fe (class me.declipsonator.chatcontrol.util.CharArgumentType) - will not be sent to client!

replacementLetters option (/filter config replacementLetters) just keeps saying Incorrect Argument for command, no matter how I put stuff in there it seems like it doesn't seem to change much.

also thanks for making this a thing, I actually needed something like this for my server

Declipsonator commented 2 years ago

I can't fix it right now, but with replacement letters, while it says its incorrect, if you use the command it still works. I will do a lot more work and try to fix all of this tonight. Command I used: /filter config replacementLetters add @ a

As with regex, personally I did not have a lot of experience with it, but that's no excuse and I will make sure that I fix that.

MrRubberDucky commented 2 years ago

I can't fix it right now, but with replacement letters, while it says its incorrect, if you use the command it still works. I will do a lot more work and try to fix all of this tonight. Command I used: /filter config replacementLetters add @ a

As with regex, personally I did not have a lot of experience with it, but that's no excuse and I will make sure that I fix that.

Ah thanks for telling me that it still works. Also, no rush. Take your time!

Declipsonator commented 2 years ago

About to test a fix for not serializing the charargumenttype, but I have a question regarding making sure regexes are not garbage. If I were to put something random, I don't see how the regex could be invalid. Example: image

Declipsonator commented 2 years ago

It may not be optimal or a good practice but I don't see a practical way to rule regexes out as faulty.

MrRubberDucky commented 2 years ago

Then that's fine, didn't realize regex can take everything and be fine with it so that's on me.

Declipsonator commented 2 years ago

I've figured out what was wrong with the regex, ends up the method I was using had a different format (so technically it did work, just wasn't really optimal). And I'll be switching it out for something more traditional.

Declipsonator commented 2 years ago

What Went Wrong

Regex

What I said above comment is actually incorrect, the reason regex wasn't working was because when checking messages, the playername section was left on. For example, if the message was <Player> baas, it would not fit the regex (?i)b(?:aa|ss)s$. To correct for this I added in some code to remove names ahead of time. When testing regex, I used .*\btesting\b.* which ignored the playername.

Replacement Letters

When making the replacementLetters command, I had to write my own command argument. What I ended up with is a CharArgumentType. Upon testing in a single player world I noticed no issues because the mod was on the client. The way the client works it is by running the parse method on every change and the server parses it when it's run. Since there is no argument on the client it just marks it wrong. From what I've seen, there is no way to fix it without installing Chat Control on the client (I do plan to eventually make chat control compatible with clients though). Since there is not much I can do here, I will just add a disclaimer in the mod descriptions.

CharArgumentType serializing

The issue here was that I forgot to register the argument in minecraft's registry. I have since done it, but it doesn't make a huge difference as the client doesn't have the CharArgumentType code anyways.

Finish

A new update will be coming out soon!

MrRubberDucky commented 2 years ago

The regex works but with a small nitpick and it's that if you're using a custom chat styling mod like Styled Chat and change ">" to let's say "»" for example, the RegEx filtering stops working but word filtering and character filtering still seems to work just fine. Here's a example: Imaeg

Aside from that, thanks for the update! It's super helpful being able to reload config on the fly and stuff 👍

Declipsonator commented 2 years ago

No problem, what I might do is make another config option on where to cut off the name or increase priority and check messages before other chat mods can get to them, glad I could help though.

MrRubberDucky commented 2 years ago

Alright, since this is solved imma close the issue.