0

I currently have this code:

    private boolean checkWildcardFilter(String contentStripped, GuildTransformer guild) {
        String words = contentStripped.toLowerCase();
        List <String> badWordsList = replace(guild.getBadWordsWildcard());
        System.out.println("UWords: " + words);
        System.out.println("FWords: " + badWordsList);
        
        return words.stream().anyMatch(badWordsList::equals);
    }

In the example apple and hi are supposed to be filtered

What I want it to do, is check the sentence "I will go and eat a grandapple with my new hire.". It needs to find the words "apple" and "hi" no matter where is is in the sentence. If it finds it, it should filter

It's in Java, and the words are coming from a database:database entry

And it decodes to: (A few curse words)

["***", "***", "***", "***"]

Community
  • 1
  • 1
stefano
  • 134
  • 7
  • 1
    Maybe this ? https://stackoverflow.com/questions/3209580/whats-the-best-way-to-parse-a-string-for-bad-words-in-c – InUser Jun 09 '20 at 12:34
  • Ohh, right @Inga I didn't explain yet, it's on discord. So I can't edit messages. And it's with Java. Not C++/C# – stefano Jun 09 '20 at 12:35
  • Also, the possible things are coming from a database, it's stored as a list with a base64 encryption – stefano Jun 09 '20 at 12:53
  • It shouldn't matter where the strings come from, be it a database and base64. The question also has nothing to do with Discord by itself. If you have trouble working with a database, with base64, or with discord, ask separate questions. – Clashsoft Jun 09 '20 at 15:08
  • Yeah, I should have explained more about it. I'm new to SOF. I'll try to improve my questions as much as possible :) – stefano Jun 10 '20 at 18:27

2 Answers2

0

I think that what you need is to check if the strings contains any sequence of characters.

If that is coming from the DB, you will need to retrieve the ones you want using appropriated queries/DB connection/etc..

If keywords are encrypted, you will have to decrypt them. There are several decryption libraries, you just need to know "what" language you are speaking

As @Clashsoft mentioned, there are multiple things you are trying to solve here. It's recommended to split them up into 3 so you have very objective questions.

For the string location, you can use this dependency:

Apache Utils

More details can be found on a similar question:

How do I check if a string contains a list of characters?

0

I've currently something I can use, I am looking for improvements though, anything I can do to improve this?

I've got something that I can use;

    private boolean checkWildcardFilter(String contentStripped, GuildTransformer guild) {
        String words = contentStripped.toLowerCase();
        List <String> badWordsList = replace(guild.getBadWordsWildcard());
        //System.out.println("UFWords: " + words);
        //System.out.println("FWords: " + badWordsList);

        for (String word : badWordsList) {
            if (words.contains(word)) {
                return true;
            }
        }
        return false;
    }
stefano
  • 134
  • 7