Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Need help with chat filter system. Can someone help?

Asked by 6 years ago

Hello, everyone!

I'm currently writing my own chat system, and I'm currently attempting to set up a chat filter. However, this only seems to work if there is one word involved ( that matches the accursed word. )

Any help would be much appreciated!

chatfilter = {}
chatfilter[1] = "badword"

s = "badword."

for w in string.gmatch(s, "%a+") do
if s == chatfilter[1] then
    print("This message contained inappropiate content.")
else
    print(s)
end
end

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You can use string.find(), if it returns nothing or nil then it can't find a bad word within a string.

Here's an example I've created.

local filteredWords = {"N00B","HATE"}

local plrString = "YOU SUCH A N00B LOLOL I HATE YOU LOLOLOL" --Typical hate speech

for i = 1, #filteredWords do
    if string.find(plrString, filteredWords[i]) ~= nil then
        print("Bad word located!")
    else
        print("Innocent words!")
    end
end

You can also track how many words were located by just having an integer that increases every time there's a bad word found.

0
Just one thing: How do I get it to filter a word no matter the capitalization? TheRings0fSaturn 28 — 6y
0
I think you need to use "%a" but i'm not sure how to give match a pattern. tobyjing2005 107 — 6y
Ad

Answer this question