0
0
Fork 0

Merge pull request 'Add global cooldown for the bed quick chat feature' (#3645) from bedantispam into master

Reviewed-on: MineClone2/MineClone2#3645
This commit is contained in:
ancientmarinerdev 2023-04-19 13:35:27 +00:00
commit becf98875f
3 changed files with 18 additions and 8 deletions

View File

@ -438,12 +438,14 @@ local playermessagecounter = {}
It gets reset after 10 secs using a globalstep
--]]
local chatbuttonused = false
local globalstep_timer = 0
minetest.register_globalstep(function(dtime)
globalstep_timer = globalstep_timer + dtime
if globalstep_timer >= 10 then
globalstep_timer = 0
playermessagecounter = {}
chatbuttonused = false
end
end)
@ -472,16 +474,22 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
end
local custom_sleep_message
if fields.chatsubmit and fields.chatmessage ~= "" then
if (not exceeded_rate_limit(player:get_player_name())) and shout_priv_check(player) then
minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage))
end
return
custom_sleep_message = fields.chatmessage
end
if fields.defaultmessage then
if custom_sleep_message or fields.defaultmessage then
if chatbuttonused then
local time_to_wait = math.ceil(10-globalstep_timer)
minetest.chat_send_player(player:get_player_name(),S("Sorry, but you have to wait @1 seconds until you may use this button again!", tostring(time_to_wait)))
return
end
if (not exceeded_rate_limit(player:get_player_name())) and shout_priv_check(player) then
minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), S("Hey! Would you guys mind sleeping?")))
chatbuttonused = true
local message = custom_sleep_message or S("Hey! Would you guys mind sleeping?")
minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), message))
end
return
end

View File

@ -46,3 +46,4 @@ send!=senden!
You are missing the 'shout' privilege! It's required in order to talk in chat...=Ihnen fehlt das 'shout' Privileg! Es wird benötigt, um im Chat reden zu können...
You exceeded the maximum number of messages per 10 seconds!=Sie haben die maximale Anzahl an Chatnachrichten pro 10 Sekunden überschritten!
Hey! Would you guys mind sleeping?=Hey, würdet Ihr bitte zu Bett gehen?
Sorry, but you have to wait @1 seconds until you may use this button again!=Sie müssen leider noch @1 Sekunden warten, bevor sie diesen Knopf erneut benutzen können!

View File

@ -46,3 +46,4 @@ send!=
You are missing the 'shout' privilege! It's required in order to talk in chat...=
You exceeded the maximum number of messages per 10 seconds!=
Hey! Would you guys mind sleeping?=
Sorry, but you have to wait @1 seconds until you may use this button again!=