diff --git a/connection.pike b/connection.pike index c2ef2428..e97ba057 100644 --- a/connection.pike +++ b/connection.pike @@ -564,6 +564,12 @@ class channel(mapping config) { vars["{cooldown}"] = vars["{cooldown_hms}"] = "0"; break; } + if (message->cdqueue) { + //As well as bouncing to the Otherwise, we queue the original message + //after the delay. (You probably don't often need an Otherwise here.) + cooldown_timeout[key] = time() + delay + message->cdlength; + call_out(_send_recursive, delay, person, message | (["conditional": 0, "_changevars": 1]), vars, cfg); + } //Yes, it's possible for the timeout to be 0 seconds. msg = message->otherwise; vars["{cooldown}"] = (string)delay; diff --git a/httpstatic/command_classic.js b/httpstatic/command_classic.js index 7d8da185..11679475 100644 --- a/httpstatic/command_classic.js +++ b/httpstatic/command_classic.js @@ -132,6 +132,7 @@ const conditional_types = { cooldown: { cdname: "(optional) Synchronization name", cdlength: "Cooldown (seconds)", //TODO: Support hh:mm:ss and show it that way for display + cdqueue: "?Queue", "": () => ["The condition passes if the time has passed.", BR(), "Use ", CODE("{cooldown}"), " for the remaining time, or ", CODE("{cooldown_hms}"), " in hh:mm:ss format.", BR(), diff --git a/httpstatic/command_gui.js b/httpstatic/command_gui.js index 35289815..8c33a968 100644 --- a/httpstatic/command_gui.js +++ b/httpstatic/command_gui.js @@ -486,7 +486,8 @@ const types = { color: "#aacc55", children: ["message", "otherwise"], label: el => [el.cdlength + "-second cooldown", "If on cooldown:"], params: [{attr: "conditional", values: "cooldown"}, {attr: "cdlength", label: "Delay (seconds)", values: [1, 86400, 1]}, //TODO: Support hh:mm:ss and show it that way for display - {attr: "cdname", label: "Tag (optional)", values: cooldown_name}], + {attr: "cdname", label: "Tag (optional)", values: cooldown_name}, + {attr: "cdqueue", label: "Queue", values: bool_attr}], typedesc: ["Prevent the command from being used too quickly. If it's been used recently, the second block happens instead.", BR(), "To have several commands share a cooldown, put the same tag in each one (any word or phrase will do)."], }, diff --git a/modules/http/chan_commands.pike b/modules/http/chan_commands.pike index aace5dfd..a3ce30f5 100644 --- a/modules/http/chan_commands.pike +++ b/modules/http/chan_commands.pike @@ -222,7 +222,7 @@ constant condition_parts = ([ "regexp": ({"expr1", "expr2", "casefold"}), "number": ({"expr1"}), //Yes, expr1 even though there's no others - means you still see it when you switch (in the classic editor) "spend": ({"expr1", "expr2"}), //Similarly, this uses the same names for the sake of the classic editor's switching. - "cooldown": ({"cdname", "cdlength"}), + "cooldown": ({"cdname", "cdlength", "cdqueue"}), ]); string normalize_cooldown_name(string|int(0..0) cdname, mapping state) {