use external table instead of internal local

This commit is contained in:
octacian 2016-06-24 12:59:34 -07:00
parent d987d9d7ff
commit a2a6f3bfaa
2 changed files with 49 additions and 75 deletions

View File

@ -1,66 +1,36 @@
-- mods/servertools/filter.lua
--[[ language filter to automatically kick and or ban players.]]--
-- WARNING: BELOW TABLE CONTAINS EXLICIT LANGUAGE FOR FILTERING PURPOSES
-- warnable
local WARNABLE = {
{ warn = "fudge" },
{ warn = "crap" },
{ warn = "damn" },
{ warn = "danm" },
{ warn = "omg" },
{ warn = "my god" },
}
-- kickable
local KICKABLE = {
{ kick = "fuck" },
{ kick = "fukc" },
{ kick = "fuk" },
{ kick = "shit" },
{ kick = "ass" },
{ kick = "wtf" },
{ kick = "f*ck" },
{ kick = "sh*t" },
{ kick = "bull" },
{ kick = "dick" },
{ kick = "bitch" },
}
-- banable
local BANABLE = {
{ ban = "sex" },
{ ban = "boob" },
{ ban = "breast" },
{ ban = "penis" },
{ ban = "vag" },
{ ban = "pussy" },
}
-- load phrase table
servertools.load_table(st.modpath.."/phrase.db")
-- if warnable word is used
for i, word in ipairs(WARNABLE) do
for i, phrase in ipairs(table) do
if phrase.type == "warn" then
minetest.register_on_chat_message(function(name, message)
local msg = message:lower()
-- ignore commands
if message:sub(1, 1) ~= "/" then
-- filter for word(s)
if msg:find(word.warn) ~= nil then
if msg:find(phrase.word) ~= nil then
-- warn player
minetest.chat_send_player(name, 'Please do not use emotional words, including "'..word.warn..'," in the chat.')
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
end
end
end)
end
end
-- if kickable word is used
for i, word in ipairs(KICKABLE) do
for i, phrase in ipairs(table) do
if phrase.type == "kick" then
minetest.register_on_chat_message(function(name, message)
local msg = message:lower()
-- ignore commands
if message:sub(1, 1) ~= "/" then
-- filter for word(s)
if msg:find(word.kick) ~= nil then
if msg:find(phrase.word) ~= nil then
-- kick player
minetest.kick_player(name, "Please use only appropriate and clean language in the public chat. Players, especially those that are younger, do not need to be hearing or using such language.")
minetest.chat_send_all("*** Kicked "..name.." for using innappropriate language.") -- print to chat
@ -69,10 +39,12 @@ for i, word in ipairs(KICKABLE) do
end
end
end)
end
end
-- if banable word is used
for i, word in ipairs(BANABLE) do
for i, phrase in ipairs(table) do
if phrase.type == "ban" then
minetest.register_on_chat_message(function(name, message)
local msg = message:lower()
-- ignore commands
@ -87,4 +59,5 @@ for i, word in ipairs(BANABLE) do
end
end
end)
end
end

1
phrase.db Normal file
View File

@ -0,0 +1 @@
return {{["type"] = "warn", ["word"] = "fudge"}, {["type"] = "warn", ["word"] = "crap"}, {["type"] = "warn", ["word"] = "damn"}, {["type"] = "warn", ["word"] = "omg"}, {["type"] = "warn", ["word"] = "my god"}, {["type"] = "kick", ["word"] = "fuck"}, {["type"] = "kick", ["word"] = "fukc"}, {["type"] = "kick", ["word"] = "fuk"}, {["type"] = "kick", ["word"] = "f*ck"}, {["type"] = "kick", ["word"] = "shit"}, {["type"] = "kick", ["word"] = "sh*t"}, {["type"] = "kick", ["word"] = "ass"}, {["type"] = "kick", ["word"] = "wtf"}, {["type"] = "kick", ["word"] = "bull"}, {["type"] = "kick", ["word"] = "dick"}, {["type"] = "kick", ["word"] = "bitch"}, {["type"] = "ban", ["word"] = "sex"}, {["type"] = "ban", ["word"] = "boob"}, {["type"] = "ban", ["word"] = "breast"}, {["type"] = "ban", ["word"] = "penis"}, {["type"] = "ban", ["word"] = "vag"}, {["type"] = "ban", ["word"] = "pussy"}}