How would I filter custom emojis

[spoiler]cc @Real_BenTheMiner @PotatoCommuter[/spoiler]
Hello. I am working on a custom chat system for a Roblox game, and it has the functionality to provide users with custom emojis. These work perfectly fine.

The game in question, however, is a transit game (Potato City Subway), and we are giving users access to route bullets for better roleplay and interactivity.
image

example above

The issue is, this flies entirely over roblox’s filter, and inputting swears does not provoke the chat filter at all. We want to give a way for the chat filter to actually recognize these to check for swears and banned words, but we aren’t sure how.

It seems nobody else has encountered such a problem, and because we want a vast variety of emojis, a solution has been hard to come by.

Any help would be greatly appreciated with this problem.

Should be tested in game. In studio for some reason every chat or text service do not filtering the bad words. You can also build a more advanced system using the documentation and ChatService to filter messages player-to-player. The code example below will work for everyone

local TextService = game:GetService("TextService")

-- mapping
local emojiMap = {
	[":alpha_C:"] = "C",
	[":alpha_U:"] = "U",
	[":alpha_F:"] = "F",
	[":alpha_K:"] = "K",
	[":alpha_A:"] = "A",
	[":alpha_H:"] = "H",
}

-- converting raw message with emojis to text using emojiMap
local function ConvertString(rawMessage)
	local replaced = rawMessage

	for code, replacementText in pairs(emojiMap) do
		replaced = string.gsub(replaced, code, replacementText)
	end

	return replaced
end

local function FilterChatMessage(player, rawMessage)
	local convertedString = ConvertString(rawMessage)

	-- using roblox filter to check the message
	local success, result = pcall(function()
		return TextService:FilterStringAsync(convertedString, player.UserId)
	end)

	if success and result then
		-- get the string filtered by roblox
		local filteredString = result:GetNonChatStringForBroadcastAsync() -- Returns the text in a properly filtered manner for all users (Documentation)

		-- comparing the filtered string to the converted string so if is changed like from "Hello" to "####" we catch that
		if filteredString ~= convertedString then
			-- returning hashes or filtered string (as you wish)
			return "####" 
		else
			-- return the original rawMessage so we can render emojis and the rest
			return rawMessage
		end
	else
		warn(`TextService filter failed : {result}`)
		return "####" -- fail safe
	end
end

-- example debug
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local userMessage = ":alpha_F: :alpha_F: :alpha_F: :alpha_F:"
	local finalMessage = FilterChatMessage(player, userMessage)
	print(finalMessage)
end)

Create a mapping between emojis and either text or built-in letter emoji codes and filter the text after you have replaced that part with the mapping. After you get the filter result, if that part doesn’t contain tags in it (if it hasn’t been filtered), put the custom emojis back at that point (by reversing the initial mapping you did) and show it to the target player.

Just a quick shout- You are no longer allowed to make or use custom chat systems in your roblox game.
So just be careful when making your game, as it may be deleted or get your account suspended

Where did you get this information from? I’ve been trying really hard to find something about it, but all I could find was this — Are custom chat GUIs no longer going to be allowed?

Not long ago, when they switched all experiences to TextChatService it was in the announcement I think… I have terrible memory so I can’t remember though.

I’ll do some research.

Found it:


On the other hand, you can make your own UI

So you can make your own chat system, but you have to use TextChatService to handle the messages

Yeah, you can design your own UI
(I’m not quite sure how you hook that up with TextChatService though)

Oh yeah, I see. This is harder to do now. It’s still possible, but you have to do quite a bit more work

This uses TextChatService, so we’re good. Thanks for the heads up

This is actually really smart, we will be implementing this very shortly. Thank you!

..I’ve run into an issue implementing this, I can’t filter this without breaking TOS(unless there is another way?)… I can’t filter locally, the only way to get it filtered it seems is to actually send it, but that is the non emoji version which is not what I want. Is there anything I can do from here?