#Creating a chat Filter

1 messages · Page 1 of 1 (latest)

restive geode
#

So I'm making a swear filter using an Array and I'm having trouble with the chat event being called.
Here's the code in my main that registers the chatlistenr

public static LearningSpigot plugin;
public void onEnable() {
....
 pm.registerEvents(new ChatListener(this), this);
merry patio
#

type hell in chat

#

and see what it does

restive geode
#

I did I type different swears and it sends the message as normal

#

Let me try putting message.contains instead of equals ignore case

wanton elk
#

To lower case the message before contains chekc

restive geode
#

That did not work

#

oh wait

#

I just checked console

wanton elk
#

Paste the error

restive geode
merry patio
#

@restive geode updated code

restive geode
novel heart
clear dew
#

yes they did, or it would not be trying to pass the event.

#

the issue appears to be that you are indexing your array from 1

#

its trying to get array pos 0

#

that is null

#

cannot compare null

restive geode
#

aahh I always forget about arrays starting at 0

clear dew
#

you indexed your array from 1 but looped from 0

#

so, yeah

#

also this appears to only filter chat if their message is only exactly one of the swear words?

restive geode
#

no it works if the message contains other strings + swears

#

Also it works now

#

thanks for your help

clear dew
#

oh, the contains

#

however, this filter is susceptible to the clbuttic mistake

#

type the word classic, which is a valid non-swear word but it contains the substring ass

#

your filter will say "bad word"

restive geode
#

yeah It's very arachic. I don't even have it setup so that ops can add filters without re-compiling

#

I just wanted to get it setup first

clear dew
#

alrighty

#

filters are not easy to make, which you'll probably soon come to realize. but good luck!

restive geode
#

Thanks for your help, I'm actually a freshman in college right now so I'm making this to learn Java

wanton elk
#

Adding config variables isnt hard

clear dew
#

yep it is good practice. but the problem itself is difficult, specially in figuring out how to fix the clbuttic mistake. it's actually a notorious problem in computer science

#

but, have fun

#

https://en.wikipedia.org/wiki/Scunthorpe_problem

if interested. will take my leave now

The Scunthorpe problem is the unintentional blocking of websites, e-mails, forum posts or search results by a spam filter or search engine because their text contains a string (or substring) of letters that appear to have an obscene or otherwise unacceptable meaning. Names, abbreviations, and technical terms are most often cited as being affecte...

tidal widget
#

or actually, learning basic logic

#

then, you would get the message to lowercase

#

split the message into words

#

check if array of bad words contains any word from the message

#

if it does, do what you want it to do