From 65aa185ffa7ed5d31aaed1498cca7392ede5e1bc Mon Sep 17 00:00:00 2001
From: chmodsayshello <chmodsayshello@hotmail.com>
Date: Sat, 15 Apr 2023 17:09:37 +0200
Subject: [PATCH 1/3] global 'bed button' cooldown

---
 mods/ITEMS/mcl_beds/functions.lua | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua
index 56e4a232b..2ca620236 100644
--- a/mods/ITEMS/mcl_beds/functions.lua
+++ b/mods/ITEMS/mcl_beds/functions.lua
@@ -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)
 
@@ -480,7 +482,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
 	end
 
 	if fields.defaultmessage then
+		if chatbuttonused then
+			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(math.ceil(10-globalstep_timer))))
+			return
+		end
+
 		if (not exceeded_rate_limit(player:get_player_name())) and shout_priv_check(player) then
+			chatbuttonused = true
 			minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), S("Hey! Would you guys mind sleeping?")))
 		end
 		return

From 326e805798d370fa16b4e483ea99972b4a8af94b Mon Sep 17 00:00:00 2001
From: chmodsayshello <chmodsayshello@hotmail.com>
Date: Sat, 15 Apr 2023 17:11:47 +0200
Subject: [PATCH 2/3] update translation stuff

---
 mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr | 3 ++-
 mods/ITEMS/mcl_beds/locale/template.txt   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr
index ae035f3bb..97867b44b 100644
--- a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr
+++ b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr
@@ -45,4 +45,5 @@ Chat:=Chat:
 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?
\ No newline at end of file
+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!
\ No newline at end of file
diff --git a/mods/ITEMS/mcl_beds/locale/template.txt b/mods/ITEMS/mcl_beds/locale/template.txt
index dd58d74e8..42e59509e 100644
--- a/mods/ITEMS/mcl_beds/locale/template.txt
+++ b/mods/ITEMS/mcl_beds/locale/template.txt
@@ -45,4 +45,5 @@ Chat:=
 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?=
\ No newline at end of file
+Hey! Would you guys mind sleeping?=
+Sorry, but you have to wait @1 seconds until you may use this button again!=
\ No newline at end of file

From b374301ebfb8a4502ae81619140b75264957c08c Mon Sep 17 00:00:00 2001
From: ancientmarinerdev <ancientmariner_dev@proton.me>
Date: Wed, 19 Apr 2023 13:54:25 +0100
Subject: [PATCH 3/3] Throttle applies to default or custom sleep message

---
 mods/ITEMS/mcl_beds/functions.lua | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua
index 2ca620236..59eea5f33 100644
--- a/mods/ITEMS/mcl_beds/functions.lua
+++ b/mods/ITEMS/mcl_beds/functions.lua
@@ -474,22 +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
-			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(math.ceil(10-globalstep_timer))))
+			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
 			chatbuttonused = true
-			minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), S("Hey! Would you guys mind sleeping?")))
+			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