What can I do to prevent spamming the SAME word multiple times in every message. When done, it would display a “Warning” message
Its different than usual spamming, as it would not warn per usual spam, I am focusing on spamming the same word per message. Like spamming dots, etc
Let me explain,
Most chat spam prevention systems warn/kick users sending messages too fast, which is a nice method to clear spammers. But, the system I am looking for is that when a person spams a word per message continuously in a given amount of time, he/she would get a warning
P1 - Noob! - 12:00pm
P2 - No, I am new! - 12:01pm
P1 - L - 12:01pm
P1 - L - 12:01pm
P1 - L - 12:01pm
Player 1 was warned
Other scenarios can be for Bots who copy paste the same message etc
The time span of ever spam message difference could be 1 min, which means no usage of the same word/sentence in a message in the same minute
This could be a bit of a complicated example since spam can come in numerous forms. Filter functions should be able to help you apply multiple filters here such as on a per-character basis and per-word basis if that’s what you’re trying to achieve.
Could you give some specific examples of what you may consider spam and flaggable if done within the same sent message? It would be more helpful to see exactly what kinds of phrases you want to be preventing from being sent.
You can make so if player sends messages faster then X amount of time it will check if there are any blacklisted words from your methatable. Like if player repeats same word in messages it will blacklist work (insert in metatable) and if player send again message with same word they will get warn/kick or whatever.
I’d write down a table that contains their past 3 messages, then compare them all if they’re duplicates - hence, warning them if so. Alongside, coroutine is used to remove old messages, so it doesn’t affiliate over time. Here’s a sample:
game.Players.PlayerAdded:Connect(function(plr)
local msgs = {}
plr.Chatted:Connect(function(msg)
msgs[3] = msgs[2]; msgs[2] = msgs[1]; msgs[1] = msg --sorting order
local duplicateMsgs = 0
for _, i in pairs(msgs) do
if i == msg then duplicateMsgs += 1 end --if duplicate then adds 1
end
if duplicateMsgs == 3 then --if all 3 are duplicates then
print(plr.Name.." has spammed")
--warning stuff here
msgs = {} --resets
end
coroutine.wrap(function() --so wait() doesn't interfere by yielding
wait(3) --amount of time until message resets
for pos, i in pairs(msgs) do
if i == msg then msgs[pos] = nil; break end
end
end)()
end)
end)
local chatService = require(ServerScriptService:WaitForChild('ChatServiceRunner').ChatService) -- get the chatservice module
local messages = {} -- table of all the sent messages
local times = {} -- table of how many times a player has sent the same message
chatService:RegisterProcessCommandsFunction('antispam', function(speakerName, message)
if messages[speakerName] == message and times[speakerName] >= 2 then -- check
coroutine.wrap(function() -- dont know if i need to use a coroutine here
wait(1.5) -- reset after 1.5 seconds
messages[speakerName] = nil
times[speakerName] = nil
end)()
-- warn player here
return true -- delete the message
end
messages[speakerName] = message
times[speakerName] = (times[speakerName] or 0) + 1
coroutine.wrap(function()
wait(60) -- reset how many times after a minute
times[speakerName] = (times[speakerName] or 1) - 1
end)()
return false -- dont delete the message
end)