local TextChatService = game:GetService("TextChatService")
local rbxGeneralChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXGeneral")
local CENSOR_WORDS = {
"test","notallowed","LOL"
}
--//The function that includes various options/possible ways to writing the bad words
local function generateVariations(word)
local variations = {}
local function helper(current, index)
if index > #word then
table.insert(variations, current)
return
end
-- Include the current character without space
helper(current .. word:sub(index, index), index + 1)
-- Include the current character with space (if not the last character)
if index < #word then
helper(current .. word:sub(index, index) .. " ", index + 1)
end
end
helper("", 1)
return variations
end
--//The function that handles the filter/replacing the bad words with other characters
local function doFilter(messageObject)
local getOriginalMessage = messageObject.Text
--print("Original Message: " .. getOriginalMessage)
for _, word in pairs(CENSOR_WORDS) do
local variations = generateVariations(word)
for _, variation in ipairs(variations) do
local pattern = variation:gsub("(%a)", function(c) return "[" .. c:lower() .. c:upper() .. "]" end)
if getOriginalMessage:match(pattern) then
messageObject.Text = getOriginalMessage:gsub(pattern, "####")
end
end
end
end
--//When we recieve a message
TextChatService.OnIncomingMessage = function(textChatMessage)
local textChatMsgProperties = Instance.new("TextChatMessageProperties")
print(textChatMessage.Text)
doFilter(textChatMessage)
return textChatMsgProperties
end
what IT basically does - replaces the bad words with hashTAGS in chat