diff --git a/.luacheckrc b/.luacheckrc index 15eed66..3c8acff 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -10,6 +10,6 @@ read_globals = { "PseudoRandom", "ItemStack", "intllib", "default", + "rules", table = { fields = { "copy", "getn" } } } - diff --git a/LICENSE b/LICENSE index cabf76e..d45568b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License -Copyright (c) 2017 Auke Kok +Copyright (c) 2017-8 Auke Kok +Copyright (c) 2018 rubenwardy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/depends.txt b/depends.txt index e69de29..5f590f8 100644 --- a/depends.txt +++ b/depends.txt @@ -0,0 +1 @@ +rules? diff --git a/init.lua b/init.lua index ae9933a..8c29e1a 100644 --- a/init.lua +++ b/init.lua @@ -1,7 +1,8 @@ --[[ - Copyright 2017 Auke Kok + Copyright 2017-8 Auke Kok + Copyright 2018 rubenwardy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -86,17 +87,39 @@ function filter.mute(name, duration) end) end +function filter.show_warning_formspec(name) + local formspec = "size[7,3]bgcolor[#080808BB;true]" .. default.gui_bg .. default.gui_bg_img .. [[ + image[0,0;2,2;filter_warning.png] + label[2.3,0.5;Please watch your language!] + ]] + + if minetest.global_exists("rules") and rules.show then + formspec = formspec .. [[ + button[0.5,2.1;3,1;rules;Show Rules] + button_exit[3.5,2.1;3,1;close;Okay] + ]] + else + formspec = formspec .. [[ + button_exit[2,2.1;3,1;close;Okay] + ]] + end + minetest.show_formspec(name, "filter:warning", formspec) +end + function filter.on_violation(name, message) violations[name] = (violations[name] or 0) + 1 local resolution - if violations[name] >= 3 then - resolution = "kicked" - minetest.kick_player(name, "Please mind your language!") - else + if violations[name] == 1 and minetest.get_player_by_name(name) then + resolution = "warned" + filter.show_warning_formspec(name) + elseif violations[name] <= 3 then resolution = "muted" filter.mute(name, 1) + else + resolution = "kicked" + minetest.kick_player(name, "Please mind your language!") end minetest.log("action", "VIOLATION (" .. resolution .. "): <" .. name .. "> ".. message) @@ -153,4 +176,12 @@ minetest.register_chatcommand("filter", { end, }) +if minetest.global_exists("rules") and rules.show then + minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "filter:warning" and fields.rules then + rules.show(player) + end + end) +end + filter.init() diff --git a/readme.md b/readme.md index 8193ce3..3b2c979 100644 --- a/readme.md +++ b/readme.md @@ -18,4 +18,3 @@ the time expires, not before. - the `shout` priv is permanently lost if the server shuts down while a player is muted. - diff --git a/textures/filter_warning.png b/textures/filter_warning.png new file mode 100644 index 0000000..da4ea7b Binary files /dev/null and b/textures/filter_warning.png differ