Ignore casing when comparing strings?

I’m working on a chat filter system (for bot-like messages) and I have a table of messages that I would substitute for hashtags if it detected them in a chat message. IDK if that made sense. Basically, if I was to say, “get free Robux here!!! → rbx.gg” then it would turn out like, “get ########## here!!! → ######”. The problem is when I am comparing the message sent to the table of messages that I have. For example, if I had “robux” on the list then the bot could just send a message like, “get Robux” instead of, “get robux” to “bypass” the check. To fix this, I did string.lower() to the message sent and then compared it to the table (all my possible scam messages) but the problem with that is when a person would send a message, it would be lowercase no matter what. I tried storing what was uppercase before I lower it and then make it uppercase after I have filtered it but it didn’t really work and would take like hours to add all the letters for it to work ok. Is there a better way of doing this? Thanks!

1 Like

You should be aware that ROBLOX has a rule when it comes to creating your own custom chat GUIs: you must use ROBLOX’s official filter. If you don’t your game could get shut down.

This article on the Developer site should go over how to filter chat in accordance with ROBLOX’s rules.

1 Like

I’m not filtering for swear words, just words like “get free robux” or “rbx.gg” and stuff like that. Am I still not allowed to do that? I’ll go read the article.

BTW Its not a custom chat GUI its the Roblox chat just a modification in a module script.

1 Like
1 Like

I suppose you could filter for stuff like that if you wanted to. Just make sure you use ROBLOX’s official filter as well.

I would definitely take all chat messages and use string.lower() on them like you were talking about. I’d probably use string.find() to look for keywords in messages and have a table with a list of words like “free robux” and “freerobux” to account for spacing. I recommend putting the list in one big table in one single script so that you can add or remove words easily.

Some pseudocode:

local function customFilter(line) --Make sure you run this line through ROBLOX's filter first!
    local badWords = {"robux", "freerobux"} --Your list of bad words go here
    line = string.lower(line) --Make all the characters lowercase
    for _, badWord in pairs(badWords) do
        local newLine, matches = line:gsub(badWord, "####")
        line = newLine --Seems gsub works best here
    end
    return line
end
1 Like

Captchas are not effective at all. This one uses colors which (I think) are textbuttons that are colored so if you were an exploiter, you could just check what the textlabel says, if it says choose orange then loop through all the textbuttons and find the one which color is orange (or just fire them all). I made my own captcha system where it was a bunch of imagelabels which were distorted versions of letters and you had to write the letters that were showed. This is still bypassable pretty easily. You just find the rbxassetid of all the letters (26 for my captcha [were randomized every time]) and assign the rbxassetid to a letter. Harder but still possible for a dedicated exploiter. Another way to bypass captchas is to delete the GUI altogether. You could fix this by deleting your character on the server or something until you complete the captcha but that is still bypassable if your sending a remote event.

1 Like

Thanks for more info. I am also using Roblox’s filter as well as my own. The pseudocode that you gave is basically mine but how would I convert the lowered string into what it was before? Because in my game, if you say “HELLO” it would turn into “hello”.

1 Like

Oh yeah, I didn’t really consider that. Sorry.

In that case, you’re gonna wanna read about String Patterns. There’s a nice diagram of the many string patterns you can use. I think the %a pattern is most likely the one you want as it ignores whether a string is uppercase or lowercase. Incorporate string patterns into your code and forget about string.lower() and that should do the trick.

1 Like

Thank you, this will probably help!

Ok, so after reading a bit more about string patterns, how would I implement this into my code? If I use %a that only checks for if it is uppercase or lowercase. It does not just ignore if they are uppercase or lowercase. For example, I can’t check if it is “robux” or if it is “free” I can only check if it has uppercase and lowercase letters. EXAMPLE:

local testTable = {
	"robux",
	"free"
}
for i,v in pairs(testTable) do
	if string.match(v, "%a") then
		print("found")
	end
end

It print found twice because both “robux” and “free” have lowercase letters.

Upon doing a bit of research I’ve found Lua is pretty bad at case-insensitive pattern replacement.

Here is what I’ve come up with. The result should be gimme #### ##########.

local example = "gimme some free robux"
local badWords = {"free robux", "some"}

local function replaceChar(pos, str, r)
	return str:sub(1, pos - 1) .. r .. str:sub(pos + 1)
end

local function customFilter(line) --Run this through ROBLOX's filter first
	local tempLine = string.lower(line) --Create a copy of the line that is all lowercase
	local partsToReplace = {}
	for _, badWord in pairs(badWords) do
		local searchStart = 1
		repeat
			local wordS, wordE = string.find(tempLine, badWord, searchStart)
			if wordS ~= nil then
				table.insert(partsToReplace, {wordS, wordE})
				searchStart = wordE + 1 --Search again further up the string
			end
		until string.find(tempLine, badWord, searchStart) == nil
	end
	--Now that we have the bad word positions stored in 'partsToReplace', replace them in the original line
	for _, replace in pairs(partsToReplace) do
		for strNum = replace[1], replace[2] do
			line = replaceChar(strNum, line, "#")
		end
	end
	return line
end

print(customFilter(example))

I would try to avoid having bad words that could overlap. Otherwise, this should work for your needs.

1 Like

Thank you so much, this actually works! I will look at how this works later but thanks for the help!