mirror of
https://github.com/thelounge/thelounge.git
synced 2024-05-02 06:33:19 +02:00
Add /wait command to commands input
This commit is contained in:
parent
e4e57b00c0
commit
d9ce50583e
|
@ -271,7 +271,11 @@
|
|||
class="tooltipped tooltipped-ne tooltipped-no-delay"
|
||||
aria-label="One /command per line.
|
||||
Each command will be executed in
|
||||
the server tab on every connection."
|
||||
the server tab on every connection.
|
||||
|
||||
If you want to wait for a time between
|
||||
commands, you can use `/wait <seconds>`,
|
||||
like `/wait 5`."
|
||||
>
|
||||
<button class="extra-help" />
|
||||
</span>
|
||||
|
|
|
@ -6,6 +6,8 @@ const Msg = require("../../models/msg");
|
|||
const Chan = require("../../models/chan");
|
||||
const Helper = require("../../helper");
|
||||
|
||||
const MAX_DELAY_LENGTH_SECONDS = 10;
|
||||
|
||||
module.exports = function (irc, network) {
|
||||
const client = this;
|
||||
|
||||
|
@ -39,15 +41,34 @@ module.exports = function (irc, network) {
|
|||
let delay = 1000;
|
||||
|
||||
if (Array.isArray(network.commands)) {
|
||||
network.commands.forEach((cmd) => {
|
||||
setTimeout(function () {
|
||||
client.input({
|
||||
target: network.channels[0].id,
|
||||
text: cmd,
|
||||
});
|
||||
}, delay);
|
||||
delay += 1000;
|
||||
});
|
||||
const commands = network.commands.map(
|
||||
(cmd) =>
|
||||
new Promise((resolve) => {
|
||||
if (cmd.toLowerCase().startsWith("/wait")) {
|
||||
try {
|
||||
delay = parseInt(cmd.substring(6), 10) * 1000;
|
||||
|
||||
if (delay > MAX_DELAY_LENGTH_SECONDS * 1000) {
|
||||
delay = MAX_DELAY_LENGTH_SECONDS * 1000;
|
||||
}
|
||||
} catch {
|
||||
delay = 1000;
|
||||
}
|
||||
|
||||
resolve();
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
client.input({
|
||||
target: network.channels[0].id,
|
||||
text: cmd,
|
||||
});
|
||||
resolve();
|
||||
}, delay);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
Promise.all(commands);
|
||||
}
|
||||
|
||||
network.channels.forEach((chan) => {
|
||||
|
|
Loading…
Reference in a new issue