More efficient method of appropriately filtering strings

Currently, we have FilterStringForPlayerAsync to filter messages for custom chat GUIs and such.
The problem is, the recommended usage of this method is very inefficient. Every time someone chats, we are supposed to filter the message separately for every player in the game.

My game has 20-player servers. So every time someone chats, that’s 20 external requests that would have to be made. When there’s a lot of people sending messages at once, there’s so many filtering requests being made that some of them start to outright fail. Message delivery is heavily delayed (the delay can be over a minute!) or never completed at all.

We only need 2 variations of a string: whitelist-filtered and blacklist-filtered. So why do we have to send an external filtering request for every single player?

This is why I’m requesting a new function and a new property to allow for a more efficient way of handling string filtering:

function game:GetService(“Chat”):GetFilteredStringsAsync( string stringToFilter, Player playerToFilterFor )
Returns 2 strings: WhitelistedString, BlacklistedString.
The Player argument is optional. If designated, the string will be filtered according to that player’s chat settings. (so if an under-13 player chats, both returned strings will be whitelist-filtered)

bool Player.UsesWhitelistChat
True if the player uses whitelist chat, false for blacklist chat.

Rather than making a separate request for every player in the game, you can just make 1 request to get both of the filtered strings that you need. Then you can appropriately distribute the messages to each player based on their chat settings, like such:

[code]local chat = game:GetService(“Chat”)

game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(message)
local WhitelistedString, BlacklistedString = chat:GetFilteredStringsAsync(message, player)
for _,recipient in pairs(game.Players:GetChildren()) do
if recipient.UsesWhitelistChat then
DistributeMessage(recipient, WhitelistedString)
else
DistributeMessage(recipient, BlacklistedString)
end
end
end)
end)[/code]

I agree with what Echo said a while ago – we should stop clogging up very dense objects like the Player class with properties and functions. I think that instead of Player.UsesWhitelistChat, we should have game:GetService(“Chat”):GetUsesWhitelistChat(Player player) [I’m bad at naming things]

Overall though, great suggestion. :DDD

It would be much simpler for the game server to be aware if a player is over or under 13. Then GetFilteredStringsAsync can send at most two requests: one for players under 13 and one for the rest. It would probably be safe to cache the filter results for the duration of the game server, or at least for some arbitrary amount of time.

I believe ROBLOX isn’t allowed to release this sort of information about it’s users to “third parties”. Even a rough estimate of their age.

Couldn’t you just filter a string with a word not on the white-list and check the result to figure out if they’re 13 or older?

Actually that gives me an idea. You could use the above once on each player when they join to decide who to send filtered messages to. :smiley:

Couldn’t you just filter a string with a word not on the white-list and check the result to figure out if they’re 13 or older?

Actually that gives me an idea. You could use the above once on each player when they join to decide who to send filtered messages to. :D[/quote]

Yup. This is actually the method I used to reduce the lag in my chat. With this information, I just filter the string for the sender, and if the sender is over 13, use an under-13 player to filter the whitelisted version of the string. Then I deliver the correct strings to the appropriate players.

It’s an awfully hacky way of doing things, though, and sometimes the initial check is not 100% accurate (over-13 players getting marked as under-13s for whatever reason) so I have to recheck all of the players periodically. It would be nice to have an official method for all this.

As long as the property is named as a chat setting, rather than “IsUnder13” or something, it ought to be totally fine.