mirror of
https://github.com/thelounge/thelounge.git
synced 2024-06-01 13:22:29 +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"
|
class="tooltipped tooltipped-ne tooltipped-no-delay"
|
||||||
aria-label="One /command per line.
|
aria-label="One /command per line.
|
||||||
Each command will be executed in
|
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" />
|
<button class="extra-help" />
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -6,6 +6,8 @@ const Msg = require("../../models/msg");
|
||||||
const Chan = require("../../models/chan");
|
const Chan = require("../../models/chan");
|
||||||
const Helper = require("../../helper");
|
const Helper = require("../../helper");
|
||||||
|
|
||||||
|
const MAX_DELAY_LENGTH_SECONDS = 10;
|
||||||
|
|
||||||
module.exports = function (irc, network) {
|
module.exports = function (irc, network) {
|
||||||
const client = this;
|
const client = this;
|
||||||
|
|
||||||
|
@ -39,15 +41,34 @@ module.exports = function (irc, network) {
|
||||||
let delay = 1000;
|
let delay = 1000;
|
||||||
|
|
||||||
if (Array.isArray(network.commands)) {
|
if (Array.isArray(network.commands)) {
|
||||||
network.commands.forEach((cmd) => {
|
const commands = network.commands.map(
|
||||||
setTimeout(function () {
|
(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({
|
client.input({
|
||||||
target: network.channels[0].id,
|
target: network.channels[0].id,
|
||||||
text: cmd,
|
text: cmd,
|
||||||
});
|
});
|
||||||
|
resolve();
|
||||||
}, delay);
|
}, delay);
|
||||||
delay += 1000;
|
}
|
||||||
});
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
Promise.all(commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
network.channels.forEach((chan) => {
|
network.channels.forEach((chan) => {
|
||||||
|
|
Loading…
Reference in a new issue