-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaps_filter.lua
More file actions
43 lines (35 loc) · 1.46 KB
/
caps_filter.lua
File metadata and controls
43 lines (35 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
local history = dofile(minetest.get_modpath("textshield") .. "/history.lua")
local MSG_CAPS_WARNING_LABEL = minetest.settings:get("textshield_caps_warning_label")
or "Please do not write in ALL CAPS, it is considered shouting."
local MSG_CAPS_WARNING_BUTTON = minetest.settings:get("textshield_caps_warning_button") or "Understood"
local MSG_LOG_EXCESSIVE_CAPS = minetest.settings:get("textshield_log_excessive_caps") or "Excessive caps: "
local function is_all_caps(message)
local letters = {}
for c in message:gmatch("[%z\1-\127\194-\244][\128-\191]*") do
if c:match("[%aА-Яа-яЁё]") then
table.insert(letters, c)
end
end
if #letters < 5 then return false end
local joined = table.concat(letters)
return joined == joined:upper()
end
local function show_caps_warning(player_name)
local formspec = string.format([[
size[6,3]
label[0.5,1;%s]
button_exit[2,2;2,1;ok;%s]
]], MSG_CAPS_WARNING_LABEL, MSG_CAPS_WARNING_BUTTON)
minetest.show_formspec(player_name, "textshield:caps", formspec)
end
minetest.register_on_chat_message(function(name, message)
if is_all_caps(message) then
local player = minetest.get_player_by_name(name)
if player then
show_caps_warning(name)
player:set_hp(player:get_hp() - 2)
end
history.log(name, MSG_LOG_EXCESSIVE_CAPS .. message)
return true
end
end)