I want to achieve string pattern match-based username and display name banning.
local http = game:GetService("HttpService")
local plrs = game:GetService("Players")
local watch_sets = {
target_username = "AnonymizedUsername",
target_dispname = "AnonymizedDisplayName",
shirt = 144076436,
pants = 144076512,
patterns = {
"Parker%d%d$", -- ends with two digits after "Parker"
".*Parker%d%d$", -- starts with anything, and ends with two digits after "Parker"
"%u%d%d%dParker%d%d$" -- starts with an uppercase letter followed by three digits and ends with two digits after "Parker"
},
}
local kick_reasons = {
"The experience's developer has temporarily shut down the experience server. Please try again.",
"Roblox has shut down the server for maintenance. Please try again.",
"Please check your internet connection and try again.",
"Client initiated disconnect",
"Your device does not have enough memory to run this experience. Exit back to the app.",
"The status of the experience has changed and you no longer have access. Please try again later.",
}
local hooks = {
url = "<webhook url removed>",
trig_meth = {
gen = "Possible (Username, DisplayName)";
com = "Confident (Username, DisplayName, Clothes)";
noti = "<@Discord User ID Removed>";
},
hookd = {
username = "",
title = [[Username: %s
Display Name: %s
User ID: %d
Trigger Method: %s]],
type = "rich",
}
}
local function matchesAnyPattern(username, patterns)
for _, pattern in ipairs(patterns) do
if string.match(username, pattern) then
return true
end
end
return false
end
local function check_outfit(plr: Player)
local hum_des = plrs:GetHumanoidDescriptionFromUserId(plr.UserId)
if hum_des.Shirt == watch_sets.shirt and hum_des.Pants == watch_sets.pants then
return true
else
return false
end
end
local function check_name(plr: Player)
local disp_name,username = plr.DisplayName,plr.Name
if matchesAnyPattern(username,watch_sets.patterns)
or string.find(disp_name,watch_sets.target_dispname,1,true)
or string.find(username,watch_sets.target_username,1,true)
then
return true
else
return false
end
end
local function send_wh(plr: Player, tm: string)
local enc = http:JSONEncode({
embeds = {{
username = "";
title = string.format(hooks.hookd.title,plr.Name,plr.DisplayName,plr.UserId,tm);
type = "rich";
}}
})
local req = http:RequestAsync({
Url = hooks.url,
Method = "POST",
Headers = {
["Content-Type"] = "application/json";
},
Body = enc
})
end
local function add_loop(plr: Player)
local out,name = check_outfit(plr),check_name(plr)
if out and name then
send_wh(plr,hooks.trig_meth.com)
plr:Kick()
end
if name then
send_wh(plr,hooks.trig_meth.gen)
plr:Kick(kick_reasons[math.random(1,#kick_reasons)])
end
end
plrs.PlayerAdded:Connect(add_loop)
This is the entire script I’m using for posterity. For a focus on what I wish to accomplish, please pay attention to the target_username
and target_dispname
, and how basic the original username/DisplayName checking function is. It only performs a strict string match at the moment.
I wish to have this string, somehow, matched, regardless of how many character repetitions ('AnonnymizedUserrrname
instead of AnonymizedUsername
) are in the original string.
Any help is appreciated, and if none can be lended at all, that’s also okay.
Thanks!