diff options
author | cheapie <no-email-for-you@example.com> | 2015-08-09 00:19:11 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2015-08-09 00:23:44 -0500 |
commit | f6e4f38e1145b9bfb07eb50a866429d4aa53f1c5 (patch) | |
tree | 050a3f03205cfb3607d40cdb888f0ebe49545d1a | |
parent | 0bd26743ae49b076bf36a67f32e6763418d47fc1 (diff) | |
download | dropthecaps-f6e4f38e1145b9bfb07eb50a866429d4aa53f1c5.tar dropthecaps-f6e4f38e1145b9bfb07eb50a866429d4aa53f1c5.tar.gz dropthecaps-f6e4f38e1145b9bfb07eb50a866429d4aa53f1c5.tar.bz2 dropthecaps-f6e4f38e1145b9bfb07eb50a866429d4aa53f1c5.tar.xz dropthecaps-f6e4f38e1145b9bfb07eb50a866429d4aa53f1c5.zip |
Trigger on messages containing at least half capital letters
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | init.lua | 31 |
2 files changed, 25 insertions, 8 deletions
@@ -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. @@ -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 |