summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README2
-rw-r--r--init.lua31
2 files changed, 25 insertions, 8 deletions
diff --git a/README b/README
index 648ea86..b2ab314 100644
--- a/README
+++ b/README
@@ -1,2 +1,2 @@
-This is a simple mod for Minetest that kicks players that send 3 all-caps messages of more than 16 characters each.
+This is a simple mod for Minetest that kicks players that send 3 messages of more than 16 characters each that are at least half capital letters.
It will also send a message to all players stating that the kick occurred, and if the irc mod is installed, the same message will be sent to the IRC channel.
diff --git a/init.lua b/init.lua
index 665a031..c27ec57 100644
--- a/init.lua
+++ b/init.lua
@@ -1,5 +1,22 @@
caps_message_count={}
+local caps_percentage = function(message)
+ local upper = message:upper()
+ local lower = message:lower()
+ local total = 0
+ if message:lower() ~= message then
+ for i = 1,message:len() do
+ local mletter = message:sub(i, i)
+ local cletter = upper:sub(i, i)
+ local lletter = lower:sub(i, i)
+ if (mletter == cletter) and (mletter ~= lletter) then total = total + 1 end
+ end
+ return total/message:len()
+ else
+ return 0
+ end
+end
+
minetest.register_on_joinplayer(function(player)
local player_name = player:get_player_name()
caps_message_count[player_name] = 0
@@ -11,18 +28,18 @@ minetest.register_on_leaveplayer(function(player)
end)
minetest.register_on_chat_message(function(name, message)
- if message:len()>16 and message:lower()~=message and message:upper()==message then
+ if message:len()>16 and caps_percentage(message)>0.5 then
caps_message_count[name] = caps_message_count[name] + 1
if caps_message_count[name]>=3 then
- minetest.kick_player(name,"Sending all-caps messages is not allowed.")
- minetest.chat_send_all(string.format("* %s was kicked for sending too many all-caps messages.",name))
- if minetest.get_modpath("irc") then irc:say(string.format("* %s was kicked for sending too many all-caps messages.",name)) end
- minetest.log("action", string.format("Kicked %s for sending too many all-caps messages",name))
+ minetest.kick_player(name,"Used too many capital letters")
+ minetest.chat_send_all(string.format("* %s was kicked for using too many capital letters.",name))
+ if minetest.get_modpath("irc") then irc:say(string.format("* %s was kicked for using too many capital letters.",name)) end
+ minetest.log("action", string.format("Kicked %s for using too many capital letters",name))
else
if minetest.get_modpath("notice") then
- notice.send(name,"Sending all-caps messages is not allowed")
+ notice.send(name,"You are using too many capital letters.")
else
- minetest.chat_send_player(name,"Sending all-caps messages is not allowed.")
+ minetest.chat_send_player(name,"You are using too many capital letters.")
end
minetest.log("action",string.format("%s was warned for sending an all-caps message (%u so far)",name,caps_message_count[name]))
end