As the title implies, I am attempting to check if emojis exist in a string, check if there are too many, and if the emoji is whitelisted.
I have yet to find a conclusive way to detect emojis in a string.
I’ve tried to detect non-Latin characters, but that just resulted in Russian being flagged as an emoji, which it is definitely not.
local function isEmoji(cp)
return (cp >= 0x2600 and cp <= 0x27FF)
or (cp >= 0x1F000 and cp <= 0x1F6FF)
end
local function filterWhitelistedEmojis(text)
local count = 0
for _, cp in utf8.codes(text) do
if isEmoji(cp) then
local char = utf8.char(cp)
if not table.find(whitelistedEmojis, char) then
return false, char -- allow use of certain emojis (🔥, 🙏, etc)
end
count += 1
if count > emojilimit then
return false, "too many emojis"
end
end
end
return true
end
Any help is appreciated, thanks!