filter: improve by checking message word-by-word
fixes an issue where the filter would detect a word that was directly present in the chat message. word-by-word checking does mean that more words will be missed, but words that aren't in the message will not be accidentally detected.
This commit is contained in:
parent
4351b2d33d
commit
1d6bec612f
34
filter.lua
34
filter.lua
@ -1,5 +1,31 @@
|
||||
-- mods/servertools/filter.lua
|
||||
--[[ language filter to automatically kick and or ban players.]]--
|
||||
--[[ language filter to automatically kick and or ban players. ]]--
|
||||
|
||||
--[[
|
||||
___ ___ _ _ ___
|
||||
| __|_ _| \| | \
|
||||
| _| | || .` | |) |
|
||||
|_| |___|_|\_|___/
|
||||
|
||||
]]
|
||||
|
||||
-- [function] find in string
|
||||
local function find_word(str, word)
|
||||
if not str and not word then return end -- something's wrong
|
||||
|
||||
-- [loop] each word in str
|
||||
for iword in str:gmatch("%w+") do
|
||||
if iword == word then return true end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
__ __ _ ___ _ _
|
||||
| \/ | /_\ |_ _| \| |
|
||||
| |\/| |/ _ \ | || .` |
|
||||
|_| |_/_/ \_\___|_|\_|
|
||||
|
||||
]]
|
||||
|
||||
-- load phrase table
|
||||
local word = datalib.table.read(st.modpath.."/phrase.db")
|
||||
@ -12,7 +38,7 @@ for i, phrase in ipairs(word) do
|
||||
-- ignore commands
|
||||
if message:sub(1, 1) ~= "/" then
|
||||
-- filter for word(s)
|
||||
if msg:find(phrase.word) ~= nil then
|
||||
if find_word(msg, phrase.word) ~= nil then
|
||||
-- warn player
|
||||
minetest.chat_send_player(name, 'Please do not use emotional words, including "'..phrase.word..'," in the chat.')
|
||||
return true -- prevent message from showing in chat
|
||||
@ -30,7 +56,7 @@ for i, phrase in ipairs(word) do
|
||||
-- ignore commands
|
||||
if message:sub(1, 1) ~= "/" then
|
||||
-- filter for word(s)
|
||||
if msg:find(phrase.word) ~= nil then
|
||||
if find_word(msg, phrase.word) ~= nil then
|
||||
-- kick player
|
||||
minetest.kick_player(name, 'Please do not use emotional or innappropriate words, including "'..phrase.word..'," in the chat.')
|
||||
minetest.chat_send_all("*** Kicked "..name.." for using innappropriate language.") -- print to chat
|
||||
@ -50,7 +76,7 @@ for i, phrase in ipairs(word) do
|
||||
-- ignore commands
|
||||
if message:sub(1, 1) ~= "/" then
|
||||
-- filter for word(s)
|
||||
if msg:find(phrase.word) ~= nil then
|
||||
if find_word(msg, phrase.word) ~= nil then
|
||||
-- ban player
|
||||
xban.ban_player(name, "servertools:filter", "5h", 'Used emotional or innappropriate words, including "'..phrase.word..'," in the chat.')
|
||||
minetest.chat_send_all("*** Banned"..name.." for using innappropriate language (5 hours).") -- print to chat
|
||||
|
Loading…
x
Reference in New Issue
Block a user