Lua中的敏感词过滤

我正在为朋友制作一个discord敏感词过滤机器人,我想知道是否有高级脚本编写者可以帮助我,或者是否有更简单的完成代码的方法。

local BadWords = {
    ['poop']=true,
}

client:on('messageCreate', function(msg)
    Msg = msg.content
    local msgs = string.split(Msg,' ')
    for i,v in pairs(msgs) do
        if BadWords[v:lower()] then
            msg:reply({
                embed = {
                    fields = {
                    {name = "敏感词",value=v,inline = true},
                    },
                    color = discordia.Color.fromRGB(114, 137, 218).value,

                    --footer = os.time(),
                }
            })
            --msg:reply(('Blacklisted word: %s'):format(v))
        end
    end
    --[[table.foreach(msgs,function(i,v)
        if BadWords[i] or BadWords[v] then
            msg:reply(('Blacklisted word: %s'):format(v))
        end
    end)--]]
end)
client:run(Settings.Token)

它没有任何问题,也没有完成,但我的想法是分割或连接发送的所有单词,使其变异为单词的所有版本(例如,农场,f4rm,打 shit)然后检查BadWord列表。

我想知道的主要是是否有更有效的方法来实现这一点,或者我只需要按自己的方式做就可以了。

点赞