Skip to content

Commit

Permalink
Implement cooldown queueing since I often seem to want it
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Nov 5, 2023
1 parent 9b13149 commit e175f4d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions connection.pike
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions httpstatic/command_classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion httpstatic/command_gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)."],
},
Expand Down
2 changes: 1 addition & 1 deletion modules/http/chan_commands.pike
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e175f4d

Please sign in to comment.