Anti-Toxicity Filter v2
Error has been resolved.
About
Previously, I have (attempted) to make a script which stopped people from making toxic comments in games, such as “ur a noob” or etc. Of course, this didn’t stop people from continuing to make these such comments. Since then, I have improved it more.
FAQ
Why should I implement this?
This new version of my previous anti-toxicity filter is not only faster, but detects toxic comments more accurately then the previous version.
Your code is scuffed. Please rewrite.
Make your own. Use my API if you want: https://toxicity.plight.digital/
What are the use cases?
For example, games like “Da Hood” or FPS games are primary targets for toxic behaviours. If implemented, this could decrease it by a lot.
What does it run on?
Cloudflare Workers. Which is what makes it so fast.
Will you ever make it go private?
Maybe. If it gets enough traction, I may have to shut it down and make people sign up for it.
How do I change the sensitivity?
Set the MaxScore
to a higher (making it less sensitive) or lower (making it more sensitive) number.
Why can I still see the message?
Either the API broke, the code broke or, due to the change to TextChatService, you can still see the message but others wont.
How fast is it?
I would say around 500ms, you can test it if you want.
Code
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local HttpService = game:GetService("HttpService")
local Channels = TextChatService:WaitForChild("TextChannels")
local TextClassifier = "https://toxicity.plight.digital"
local MaxScore = 0.7
local function isMessageToxic(message: string): boolean
if message == "" then return false end
pcall(function()
response = HttpService:PostAsync(
TextClassifier,
HttpService:JSONEncode({
text = message
}),
Enum.HttpContentType.ApplicationJson
)
response = HttpService:JSONDecode(response).response
end)
if response.Error or not response then
print("There has been an error.") -- err code?
return false
end
if (tonumber(response[1].score) or 0) > (tonumber(MaxScore) or 0.7) then
return true
else
return false
end
end
local function channelAdded(channel: TextChannel)
if not channel:IsA("TextChannel") then return end
channel.ShouldDeliverCallback = function(message: TextChatMessage, speaker: TextSource)
if isMessageToxic(message.Text) then
print("Message not sent.")
return false
else
print("Message sent.")
return true
end
end
end
for _, channel in pairs(Channels:GetChildren()) do
channelAdded(channel)
end
Channels.ChildAdded:Connect(channelAdded)
You can test it here.
In case you didn’t read the FAQ, the link to the API is here.