libroadcast-cli 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -8
- package/dist/cmd/delay.js +9 -5
- package/dist/cmd/fixSchedule.js +90 -0
- package/dist/cmd/setLichessGames.js +8 -4
- package/dist/cmd/setPGN.js +9 -5
- package/dist/index.js +7 -5
- package/dist/utils/colors.js +14 -0
- package/dist/utils/commandHandler.js +6 -4
- package/dist/utils/getInfoBroadcast.js +6 -2
- package/dist/utils/help.js +60 -32
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -16,26 +16,41 @@ libroadcast
|
|
|
16
16
|
```bash
|
|
17
17
|
Usage: <command> [options]
|
|
18
18
|
|
|
19
|
+
|
|
19
20
|
Commands:
|
|
20
21
|
delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]
|
|
21
22
|
Sets the delay for all rounds in the specified broadcast.
|
|
22
|
-
The delay is specified in seconds. (max 3600 seconds = 1 hour)
|
|
23
|
+
Note: The delay is specified in seconds. (max 3600 seconds = 1 hour)
|
|
23
24
|
Options:
|
|
24
25
|
--onlyDelay Set only the delay without changing the start time.
|
|
25
26
|
--noDelay Remove the delay from the rounds.
|
|
27
|
+
|
|
26
28
|
setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]
|
|
27
29
|
Sets the source PGN URL for all rounds in the specified broadcast.
|
|
28
|
-
(optional) Use
|
|
29
|
-
|
|
30
|
+
(optional) Use "{}" in the URL as a placeholder for the round number.
|
|
31
|
+
Note: For livechesscloud URLs, please ensure it ends with "/{}".
|
|
30
32
|
Options:
|
|
31
|
-
--withFilter
|
|
32
|
-
--slice <sliceFilter>
|
|
33
|
+
--withFilter Apply round number filtering based on round number.
|
|
34
|
+
--slice <sliceFilter> Apply slice filtering using the provided filter string.
|
|
35
|
+
|
|
33
36
|
setLichessGames <broadcastRoundId> <gameIds...>
|
|
34
37
|
Sets the games for the specified broadcast round using Lichess game IDs.
|
|
35
38
|
Note: Maximum of 64 game IDs can be provided.
|
|
36
39
|
|
|
40
|
+
fixSchedule <broadcastId> <timeDiff> [--rounds <roundsToFix>]
|
|
41
|
+
Fixes the schedule of rounds in the specified broadcast by applying a time difference.
|
|
42
|
+
Note: The time difference should be in a format like "1h", "30m", "15s", etc.
|
|
43
|
+
Options:
|
|
44
|
+
--rounds <roundsToFix> Specify which rounds to fix using formats like '1-4', '8+', '3,5,7', etc.
|
|
45
|
+
|
|
46
|
+
|
|
37
47
|
Examples:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
# Set a 5-minute delay without changing start time
|
|
49
|
+
$ delay bcast123 300 --onlyDelay
|
|
50
|
+
# Set source PGN URL with round and slice filters
|
|
51
|
+
$ setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"
|
|
52
|
+
# Set Lichess games for a broadcast round
|
|
53
|
+
$ setLichessGames round456 gameId1 gameId2 gameId3
|
|
54
|
+
# Fix schedule of rounds 1 to 4 and all rounds after 8 by adding 15 minutes
|
|
55
|
+
$ fixSchedule bcast123 15m --rounds 1-4,8+
|
|
41
56
|
```
|
package/dist/cmd/delay.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.delayCommand = void 0;
|
|
4
7
|
const node_process_1 = require("node:process");
|
|
5
8
|
const commandHandler_1 = require("../utils/commandHandler");
|
|
6
9
|
const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
|
|
10
|
+
const colors_1 = __importDefault(require("../utils/colors"));
|
|
7
11
|
const setDelayRounds = async (rounds, delay, onlyDelay, noDelay) => {
|
|
8
12
|
for (const round of rounds) {
|
|
9
13
|
await commandHandler_1.client
|
|
@@ -21,12 +25,12 @@ const setDelayRounds = async (rounds, delay, onlyDelay, noDelay) => {
|
|
|
21
25
|
})
|
|
22
26
|
.then((response) => {
|
|
23
27
|
if (response.response.ok)
|
|
24
|
-
console.log(`Successfully set delay for round ${round.id} to ${delay} seconds.`);
|
|
28
|
+
console.log(colors_1.default.green(`Successfully set delay for round ${colors_1.default.whiteBold(round.id)} to ${colors_1.default.whiteBold(delay.toString())} seconds.`));
|
|
25
29
|
else
|
|
26
|
-
console.error(`Failed to set delay for round ${round.id}: ${response.response.statusText}`);
|
|
30
|
+
console.error(colors_1.default.red(`Failed to set delay for round ${colors_1.default.whiteBold(round.id)}: ${colors_1.default.whiteBold(response.response.statusText)}`));
|
|
27
31
|
})
|
|
28
32
|
.catch((error) => {
|
|
29
|
-
console.error(`Error setting delay for round ${round.id}
|
|
33
|
+
console.error(colors_1.default.red(`Error setting delay for round ${colors_1.default.whiteBold(round.id)}:`), error);
|
|
30
34
|
});
|
|
31
35
|
await (0, commandHandler_1.sleep)(200);
|
|
32
36
|
}
|
|
@@ -45,12 +49,12 @@ const delayCommand = async (args) => {
|
|
|
45
49
|
const onlyDelay = args.includes("--onlyDelay");
|
|
46
50
|
const noDelay = args.includes("--noDelay");
|
|
47
51
|
if (onlyDelay && noDelay) {
|
|
48
|
-
console.error("Cannot use --onlyDelay and --noDelay together.");
|
|
52
|
+
console.error(colors_1.default.red("Cannot use --onlyDelay and --noDelay together."));
|
|
49
53
|
(0, node_process_1.exit)(1);
|
|
50
54
|
}
|
|
51
55
|
const broadcast = await (0, getInfoBroadcast_1.getBroadcast)(broadcastId);
|
|
52
56
|
if (!broadcast?.rounds || broadcast.rounds.length === 0) {
|
|
53
|
-
console.error("No rounds found for the specified broadcast.");
|
|
57
|
+
console.error(colors_1.default.red("No rounds found for the specified broadcast."));
|
|
54
58
|
(0, node_process_1.exit)(1);
|
|
55
59
|
}
|
|
56
60
|
setDelayRounds(broadcast.rounds, parseInt(delay, 10), onlyDelay, noDelay);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fixScheduleCommand = void 0;
|
|
7
|
+
const node_process_1 = require("node:process");
|
|
8
|
+
const commandHandler_1 = require("../utils/commandHandler");
|
|
9
|
+
const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
|
|
10
|
+
const colors_1 = __importDefault(require("../utils/colors"));
|
|
11
|
+
const ms_1 = require("ms");
|
|
12
|
+
const fixScheduleRounds = async (rounds, timeDiff, roundsToFix) => {
|
|
13
|
+
if (roundsToFix && roundsToFix.length > 0) {
|
|
14
|
+
rounds = rounds.filter((_, i) => roundsToFix.includes(i + 1));
|
|
15
|
+
}
|
|
16
|
+
rounds = rounds.filter((el) => el.startsAt !== undefined);
|
|
17
|
+
for (const round of rounds) {
|
|
18
|
+
await commandHandler_1.client
|
|
19
|
+
.POST("/broadcast/round/{broadcastRoundId}/edit", {
|
|
20
|
+
params: {
|
|
21
|
+
path: { broadcastRoundId: round.id },
|
|
22
|
+
query: { patch: 1 },
|
|
23
|
+
},
|
|
24
|
+
body: {
|
|
25
|
+
startsAt: round.startsAt + timeDiff,
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
.then((response) => {
|
|
29
|
+
if (response.response.ok)
|
|
30
|
+
console.log(colors_1.default.green(`Successfully fixed schedule for round ${colors_1.default.whiteBold(round.id)}.`));
|
|
31
|
+
else
|
|
32
|
+
console.error(colors_1.default.red(`Failed to fix schedule for round ${colors_1.default.whiteBold(round.id)}: ${colors_1.default.whiteBold(response.response.statusText)}`));
|
|
33
|
+
})
|
|
34
|
+
.catch((error) => {
|
|
35
|
+
console.error(colors_1.default.red(`Error fixing schedule for round ${colors_1.default.whiteBold(round.id)}:`), error);
|
|
36
|
+
});
|
|
37
|
+
await (0, commandHandler_1.sleep)(200);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const translateRoundsToFix = (arg) => {
|
|
41
|
+
const rounds = [];
|
|
42
|
+
const parts = arg.split(",");
|
|
43
|
+
for (const part of parts) {
|
|
44
|
+
if (part.endsWith("+")) {
|
|
45
|
+
const start = parseInt(part.slice(0, -1), 10);
|
|
46
|
+
for (let i = start; i <= 64; i++) {
|
|
47
|
+
rounds.push(i);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else if (part.includes("-")) {
|
|
51
|
+
const [startStr, endStr] = part.split("-");
|
|
52
|
+
const start = parseInt(startStr, 10);
|
|
53
|
+
const end = parseInt(endStr, 10);
|
|
54
|
+
for (let i = start; i <= end; i++) {
|
|
55
|
+
rounds.push(i);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const roundNum = parseInt(part, 10);
|
|
60
|
+
rounds.push(roundNum);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return rounds;
|
|
64
|
+
};
|
|
65
|
+
const fixScheduleCommand = async (args) => {
|
|
66
|
+
const [broadcastId, timeDiffStr] = args.slice(0, 2);
|
|
67
|
+
if (!broadcastId || !timeDiffStr) {
|
|
68
|
+
(0, commandHandler_1.msgCommonErrorHelp)("Broadcast ID and time difference are required.");
|
|
69
|
+
(0, node_process_1.exit)(1);
|
|
70
|
+
}
|
|
71
|
+
const timeDiff = (0, ms_1.parse)(timeDiffStr);
|
|
72
|
+
if (isNaN(timeDiff)) {
|
|
73
|
+
console.error(colors_1.default.red("Error: Time difference must be a valid duration string (e.g., '1h', '30m', '15s')."));
|
|
74
|
+
(0, node_process_1.exit)(1);
|
|
75
|
+
}
|
|
76
|
+
console.log(`Applying time difference of ${colors_1.default.whiteBold(timeDiffStr)} (${colors_1.default.whiteBold(timeDiff.toString())} ms) to broadcast ${colors_1.default.whiteBold(broadcastId)}.`);
|
|
77
|
+
const roundsArgIndex = args.findIndex((arg) => arg === "--rounds");
|
|
78
|
+
let roundsToFix = undefined;
|
|
79
|
+
if (roundsArgIndex !== -1 && roundsArgIndex + 1 < args.length) {
|
|
80
|
+
const roundsArg = args[roundsArgIndex + 1];
|
|
81
|
+
roundsToFix = roundsArg ? translateRoundsToFix(roundsArg) : undefined;
|
|
82
|
+
}
|
|
83
|
+
const broadcast = await (0, getInfoBroadcast_1.getBroadcast)(broadcastId);
|
|
84
|
+
if (!broadcast?.rounds || broadcast.rounds.length === 0) {
|
|
85
|
+
console.error(colors_1.default.red(`Broadcast with ID ${colors_1.default.whiteBold(broadcastId)} not found or has no rounds.`));
|
|
86
|
+
(0, node_process_1.exit)(1);
|
|
87
|
+
}
|
|
88
|
+
await fixScheduleRounds(broadcast.rounds, timeDiff, roundsToFix);
|
|
89
|
+
};
|
|
90
|
+
exports.fixScheduleCommand = fixScheduleCommand;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.setLichessGamesCommand = void 0;
|
|
4
7
|
const node_process_1 = require("node:process");
|
|
5
8
|
const commandHandler_1 = require("../utils/commandHandler");
|
|
6
9
|
const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
|
|
10
|
+
const colors_1 = __importDefault(require("../utils/colors"));
|
|
7
11
|
const setLichessGames = (round, games) => commandHandler_1.client
|
|
8
12
|
.POST("/broadcast/round/{broadcastRoundId}/edit", {
|
|
9
13
|
params: {
|
|
@@ -17,12 +21,12 @@ const setLichessGames = (round, games) => commandHandler_1.client
|
|
|
17
21
|
})
|
|
18
22
|
.then((response) => {
|
|
19
23
|
if (response.response.ok)
|
|
20
|
-
console.log(`Successfully set games for round ${round.id} to ${games}.`);
|
|
24
|
+
console.log(colors_1.default.green(`Successfully set games for round ${colors_1.default.whiteBold(round.id)} to ${colors_1.default.whiteBold(games)}.`));
|
|
21
25
|
else
|
|
22
|
-
console.error(`Failed to set games for round ${round.id}: ${response.response.statusText}`);
|
|
26
|
+
console.error(colors_1.default.red(`Failed to set games for round ${colors_1.default.whiteBold(round.id)}: ${colors_1.default.whiteBold(response.response.statusText)}`));
|
|
23
27
|
})
|
|
24
28
|
.catch((error) => {
|
|
25
|
-
console.error(`Error setting games for round ${round.id}
|
|
29
|
+
console.error(colors_1.default.red(`Error setting games for round ${colors_1.default.whiteBold(round.id)}:`), error);
|
|
26
30
|
});
|
|
27
31
|
const setLichessGamesCommand = async (args) => {
|
|
28
32
|
const bId = args.shift();
|
|
@@ -33,7 +37,7 @@ const setLichessGamesCommand = async (args) => {
|
|
|
33
37
|
}
|
|
34
38
|
const round = await (0, getInfoBroadcast_1.getBroadcastRound)(bId);
|
|
35
39
|
if (!round) {
|
|
36
|
-
console.error(`Broadcast round with ID ${bId} not found or has no rounds.`);
|
|
40
|
+
console.error(colors_1.default.red(`Broadcast round with ID ${colors_1.default.whiteBold(bId)} not found or has no rounds.`));
|
|
37
41
|
(0, node_process_1.exit)(1);
|
|
38
42
|
}
|
|
39
43
|
setLichessGames(round, games);
|
package/dist/cmd/setPGN.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.setPGNCommand = void 0;
|
|
4
7
|
const node_process_1 = require("node:process");
|
|
5
8
|
const commandHandler_1 = require("../utils/commandHandler");
|
|
6
9
|
const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
|
|
10
|
+
const colors_1 = __importDefault(require("../utils/colors"));
|
|
7
11
|
const setPGN = async (rounds, urlRound, setRoundFilter, setSliceFilter = null) => {
|
|
8
12
|
for (let rN = 1; rN <= rounds.length; rN++) {
|
|
9
13
|
const round = rounds[rN - 1];
|
|
@@ -23,12 +27,12 @@ const setPGN = async (rounds, urlRound, setRoundFilter, setSliceFilter = null) =
|
|
|
23
27
|
})
|
|
24
28
|
.then((response) => {
|
|
25
29
|
if (response.response.ok)
|
|
26
|
-
console.log(`Successfully set source for round ${round.id} to ${url}.`);
|
|
30
|
+
console.log(colors_1.default.green(`Successfully set source for round ${colors_1.default.whiteBold(round.id)} to ${colors_1.default.whiteBold(url)}.`));
|
|
27
31
|
else
|
|
28
|
-
console.error(`Failed to set source for round ${round.id}: ${response.response.statusText}`);
|
|
32
|
+
console.error(colors_1.default.red(`Failed to set source for round ${colors_1.default.whiteBold(round.id)}: ${colors_1.default.whiteBold(response.response.statusText)}`));
|
|
29
33
|
})
|
|
30
34
|
.catch((error) => {
|
|
31
|
-
console.error(`Error setting source for round ${round.id}
|
|
35
|
+
console.error(colors_1.default.red(`Error setting source for round ${colors_1.default.whiteBold(round.id)}:`), error);
|
|
32
36
|
});
|
|
33
37
|
await (0, commandHandler_1.sleep)(200);
|
|
34
38
|
}
|
|
@@ -55,9 +59,9 @@ const setPGNCommand = async (args) => {
|
|
|
55
59
|
throw new Error();
|
|
56
60
|
}
|
|
57
61
|
catch {
|
|
58
|
-
console.error(isLCC
|
|
62
|
+
console.error(colors_1.default.red(isLCC
|
|
59
63
|
? 'Invalid URL. For livechesscloud URLs, please ensure it ends with "/{}".'
|
|
60
|
-
: 'Invalid URL. Must be http/https with "{}" as round placeholder.');
|
|
64
|
+
: 'Invalid URL. Must be http/https with "{}" as round placeholder.'));
|
|
61
65
|
(0, node_process_1.exit)(1);
|
|
62
66
|
}
|
|
63
67
|
const setRoundFilter = args.includes("--withFilter");
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
7
|
const node_process_1 = require("node:process");
|
|
5
8
|
const commandHandler_1 = require("./utils/commandHandler");
|
|
6
9
|
const help_1 = require("./utils/help");
|
|
10
|
+
const colors_1 = __importDefault(require("./utils/colors"));
|
|
7
11
|
(async () => {
|
|
8
12
|
if (commandHandler_1.args.includes("--version") || commandHandler_1.args.includes("-v")) {
|
|
9
13
|
const { version } = require("../package.json");
|
|
10
|
-
console.log(
|
|
14
|
+
console.log(`${colors_1.default.whiteBold("libroadcast-cli")} ${colors_1.default.underItalic(`v${version}`)}`);
|
|
11
15
|
(0, node_process_1.exit)(0);
|
|
12
16
|
}
|
|
13
17
|
if (commandHandler_1.args.length === 0 || (0, help_1.includeHelp)(commandHandler_1.args[0])) {
|
|
@@ -16,18 +20,16 @@ const help_1 = require("./utils/help");
|
|
|
16
20
|
}
|
|
17
21
|
const cmd = commandHandler_1.args.shift();
|
|
18
22
|
const handler = commandHandler_1.commands.get(cmd);
|
|
19
|
-
if (cmd === commandHandler_1.Command.SetLCC)
|
|
20
|
-
console.warn("Warning: 'setLCC' command was removed. Will use 'setPGN' instead.");
|
|
21
23
|
if (commandHandler_1.args.find(help_1.includeHelp)) {
|
|
22
24
|
(0, help_1.showHelp)(cmd);
|
|
23
25
|
(0, node_process_1.exit)(0);
|
|
24
26
|
}
|
|
25
27
|
if (!handler) {
|
|
26
|
-
console.error("Error: Command handler not found
|
|
28
|
+
console.error(`${colors_1.default.red("Error:")} Command handler not found.`);
|
|
27
29
|
(0, node_process_1.exit)(1);
|
|
28
30
|
}
|
|
29
31
|
if (!commandHandler_1.LICHESS_TOKEN) {
|
|
30
|
-
console.error("Error: LICHESS_TOKEN environment variable is not set
|
|
32
|
+
console.error(`${colors_1.default.red("Error:")} ${colors_1.default.whiteBold("LICHESS_TOKEN")} environment variable is not set.`);
|
|
31
33
|
(0, node_process_1.exit)(1);
|
|
32
34
|
}
|
|
33
35
|
await handler(commandHandler_1.args);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_util_1 = require("node:util");
|
|
4
|
+
exports.default = {
|
|
5
|
+
red: (text) => (0, node_util_1.styleText)("red", text),
|
|
6
|
+
blue: (text) => (0, node_util_1.styleText)("blue", text),
|
|
7
|
+
boldYellow: (text) => (0, node_util_1.styleText)(["bold", "yellow"], text),
|
|
8
|
+
underItalic: (text) => (0, node_util_1.styleText)(["underline", "italic"], text),
|
|
9
|
+
bold: (text) => (0, node_util_1.styleText)("bold", text),
|
|
10
|
+
italic: (text) => (0, node_util_1.styleText)("italic", text),
|
|
11
|
+
gray: (text) => (0, node_util_1.styleText)("gray", text),
|
|
12
|
+
green: (text) => (0, node_util_1.styleText)("green", text),
|
|
13
|
+
whiteBold: (text) => (0, node_util_1.styleText)(["white", "bold"], text),
|
|
14
|
+
};
|
|
@@ -9,21 +9,23 @@ const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
|
|
|
9
9
|
const delay_1 = require("../cmd/delay");
|
|
10
10
|
const setPGN_1 = require("../cmd/setPGN");
|
|
11
11
|
const setLichessGames_1 = require("../cmd/setLichessGames");
|
|
12
|
+
const fixSchedule_1 = require("../cmd/fixSchedule");
|
|
13
|
+
const colors_1 = __importDefault(require("./colors"));
|
|
12
14
|
exports.LICHESS_TOKEN = node_process_1.env.LICHESS_TOKEN;
|
|
13
15
|
const LICHESS_DOMAIN = node_process_1.env.LICHESS_DOMAIN || "https://lichess.org/";
|
|
14
16
|
exports.args = node_process_1.argv.slice(2);
|
|
15
17
|
var Command;
|
|
16
18
|
(function (Command) {
|
|
17
19
|
Command["Delay"] = "delay";
|
|
18
|
-
Command["SetLCC"] = "setLCC";
|
|
19
20
|
Command["SetPGN"] = "setPGN";
|
|
20
21
|
Command["SetLichessGames"] = "setLichessGames";
|
|
22
|
+
Command["FixSchedule"] = "fixSchedule";
|
|
21
23
|
})(Command || (exports.Command = Command = {}));
|
|
22
24
|
exports.commands = new Map([
|
|
23
25
|
[Command.Delay, delay_1.delayCommand],
|
|
24
|
-
[Command.SetLCC, setPGN_1.setPGNCommand],
|
|
25
26
|
[Command.SetPGN, setPGN_1.setPGNCommand],
|
|
26
27
|
[Command.SetLichessGames, setLichessGames_1.setLichessGamesCommand],
|
|
28
|
+
[Command.FixSchedule, fixSchedule_1.fixScheduleCommand],
|
|
27
29
|
]);
|
|
28
30
|
exports.client = (0, openapi_fetch_1.default)({
|
|
29
31
|
baseUrl: LICHESS_DOMAIN,
|
|
@@ -35,7 +37,7 @@ exports.client = (0, openapi_fetch_1.default)({
|
|
|
35
37
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
36
38
|
exports.sleep = sleep;
|
|
37
39
|
const msgCommonErrorHelp = (msg) => {
|
|
38
|
-
console.error(msg);
|
|
39
|
-
console.info("Use --help to see usage.");
|
|
40
|
+
console.error(colors_1.default.red(msg));
|
|
41
|
+
console.info(colors_1.default.blue("Use --help to see usage."));
|
|
40
42
|
};
|
|
41
43
|
exports.msgCommonErrorHelp = msgCommonErrorHelp;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getBroadcastRound = exports.getBroadcast = void 0;
|
|
4
7
|
const commandHandler_1 = require("./commandHandler");
|
|
8
|
+
const colors_1 = __importDefault(require("./colors"));
|
|
5
9
|
const getBroadcast = (broadcastId) => commandHandler_1.client
|
|
6
10
|
.GET("/api/broadcast/{broadcastTournamentId}", {
|
|
7
11
|
params: {
|
|
@@ -10,7 +14,7 @@ const getBroadcast = (broadcastId) => commandHandler_1.client
|
|
|
10
14
|
})
|
|
11
15
|
.then((response) => response.data)
|
|
12
16
|
.catch((error) => {
|
|
13
|
-
console.error("Error fetching broadcast:", error);
|
|
17
|
+
console.error(colors_1.default.red("Error fetching broadcast:"), error);
|
|
14
18
|
return null;
|
|
15
19
|
});
|
|
16
20
|
exports.getBroadcast = getBroadcast;
|
|
@@ -26,7 +30,7 @@ const getBroadcastRound = (roundId) => commandHandler_1.client
|
|
|
26
30
|
})
|
|
27
31
|
.then((response) => response.data?.round)
|
|
28
32
|
.catch((error) => {
|
|
29
|
-
console.error("Error fetching broadcast round:", error);
|
|
33
|
+
console.error(colors_1.default.red("Error fetching broadcast round:"), error);
|
|
30
34
|
return null;
|
|
31
35
|
});
|
|
32
36
|
exports.getBroadcastRound = getBroadcastRound;
|
package/dist/utils/help.js
CHANGED
|
@@ -1,45 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.includeHelp = exports.showHelp = void 0;
|
|
4
7
|
const commandHandler_1 = require("./commandHandler");
|
|
8
|
+
const colors_1 = __importDefault(require("./colors"));
|
|
9
|
+
const helpDelay = [
|
|
10
|
+
` ${colors_1.default.underItalic("delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]")}`,
|
|
11
|
+
` ${colors_1.default.gray("Sets the delay for all rounds in the specified broadcast.")}`,
|
|
12
|
+
` ${colors_1.default.bold("Note:")} ${colors_1.default.gray("The delay is specified in seconds. (max 3600 seconds = 1 hour)")}`,
|
|
13
|
+
` ${colors_1.default.bold("Options:")}`,
|
|
14
|
+
` --onlyDelay ${colors_1.default.gray("Set only the delay without changing the start time.")}`,
|
|
15
|
+
` --noDelay ${colors_1.default.gray("Remove the delay from the rounds.")}`,
|
|
16
|
+
].join("\n");
|
|
17
|
+
const helpSetPGN = [
|
|
18
|
+
` ${colors_1.default.underItalic("setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]")}`,
|
|
19
|
+
` ${colors_1.default.gray("Sets the source PGN URL for all rounds in the specified broadcast.")}`,
|
|
20
|
+
` ${colors_1.default.italic("(optional)")} ${colors_1.default.gray('Use "{}" in the URL as a placeholder for the round number.')}`,
|
|
21
|
+
` ${colors_1.default.bold("Note:")} ${colors_1.default.gray('For livechesscloud URLs, please ensure it ends with "/{}".')}`,
|
|
22
|
+
` ${colors_1.default.bold("Options:")}`,
|
|
23
|
+
` --withFilter ${colors_1.default.gray("Apply round number filtering based on round number.")}`,
|
|
24
|
+
` --slice <sliceFilter> ${colors_1.default.gray("Apply slice filtering using the provided filter string.")}`,
|
|
25
|
+
].join("\n");
|
|
26
|
+
const helpSetLichessGames = [
|
|
27
|
+
` ${colors_1.default.underItalic("setLichessGames <broadcastRoundId> <gameIds...>")}`,
|
|
28
|
+
` ${colors_1.default.gray("Sets the games for the specified broadcast round using Lichess game IDs.")}`,
|
|
29
|
+
` ${colors_1.default.bold("Note:")} ${colors_1.default.gray("Maximum of 64 game IDs can be provided.")}`,
|
|
30
|
+
].join("\n");
|
|
31
|
+
const helpFixSchedule = [
|
|
32
|
+
` ${colors_1.default.underItalic("fixSchedule <broadcastId> <timeDiff> [--rounds <roundsToFix>]")}`,
|
|
33
|
+
` ${colors_1.default.gray("Fixes the schedule of rounds in the specified broadcast by applying a time difference.")}`,
|
|
34
|
+
` ${colors_1.default.bold("Note:")} ${colors_1.default.gray('The time difference should be in a format like "1h", "30m", "15s", etc.')}`,
|
|
35
|
+
` ${colors_1.default.bold("Options:")}`,
|
|
36
|
+
` --rounds <roundsToFix> ${colors_1.default.gray("Specify which rounds to fix using formats like '1-4', '8+', '3,5,7', etc.")}`,
|
|
37
|
+
].join("\n");
|
|
5
38
|
const msg = [
|
|
6
|
-
"Usage: <command> [options]"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
""
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
' setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"',
|
|
29
|
-
" setLichessGames round456 gameId1 gameId2 gameId3 # Set specific games for the round",
|
|
39
|
+
`${colors_1.default.boldYellow("Usage:")} ${colors_1.default.underItalic("<command> [options]")}`,
|
|
40
|
+
``,
|
|
41
|
+
``,
|
|
42
|
+
`${colors_1.default.boldYellow("Commands:")}`,
|
|
43
|
+
helpDelay,
|
|
44
|
+
``,
|
|
45
|
+
helpSetPGN,
|
|
46
|
+
``,
|
|
47
|
+
helpSetLichessGames,
|
|
48
|
+
``,
|
|
49
|
+
helpFixSchedule,
|
|
50
|
+
``,
|
|
51
|
+
``,
|
|
52
|
+
`${colors_1.default.boldYellow("Examples:")}`,
|
|
53
|
+
` ${colors_1.default.gray("# Set a 5-minute delay without changing start time")}`,
|
|
54
|
+
` $ ${colors_1.default.underItalic("delay")} ${colors_1.default.italic("bcast123 300 --onlyDelay")}`,
|
|
55
|
+
` ${colors_1.default.gray("# Set source PGN URL with round and slice filters")}`,
|
|
56
|
+
` $ ${colors_1.default.underItalic("setPGN")} ${colors_1.default.italic('bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"')}`,
|
|
57
|
+
` ${colors_1.default.gray("# Set Lichess games for a broadcast round")}`,
|
|
58
|
+
` $ ${colors_1.default.underItalic("setLichessGames")} ${colors_1.default.italic("round456 gameId1 gameId2 gameId3")}`,
|
|
59
|
+
` ${colors_1.default.gray("# Fix schedule of rounds 1 to 4 and all rounds after 8 by adding 15 minutes")}`,
|
|
60
|
+
` $ ${colors_1.default.underItalic("fixSchedule")} ${colors_1.default.italic("bcast123 15m --rounds 1-4,8+")}`,
|
|
30
61
|
];
|
|
31
62
|
const showHelp = (cmd) => {
|
|
32
63
|
const ranges = {
|
|
33
|
-
[commandHandler_1.Command.Delay]:
|
|
34
|
-
[commandHandler_1.Command.SetPGN]:
|
|
35
|
-
[commandHandler_1.Command.
|
|
36
|
-
[commandHandler_1.Command.
|
|
64
|
+
[commandHandler_1.Command.Delay]: helpDelay,
|
|
65
|
+
[commandHandler_1.Command.SetPGN]: helpSetPGN,
|
|
66
|
+
[commandHandler_1.Command.SetLichessGames]: helpSetLichessGames,
|
|
67
|
+
[commandHandler_1.Command.FixSchedule]: helpFixSchedule,
|
|
37
68
|
};
|
|
38
69
|
const range = cmd ? ranges[cmd] : undefined;
|
|
39
|
-
|
|
40
|
-
console.warn("Warning: 'setLCC' command was removed. Use 'setPGN' command instead.");
|
|
41
|
-
}
|
|
42
|
-
console.info(range ? msg.slice(...range).join("\n") : msg.join("\n"));
|
|
70
|
+
console.info(range ? range : msg.join("\n"));
|
|
43
71
|
};
|
|
44
72
|
exports.showHelp = showHelp;
|
|
45
73
|
const includeHelp = (str) => ["--help", "-h"].includes(str);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libroadcast-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "CLI to help with broadcast maintenance on Lichess",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -14,9 +14,11 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@lichess-org/types": "^2.0.94",
|
|
16
16
|
"@types/node": "^24.10.0",
|
|
17
|
+
"ms": "3.0.0-canary.202508261828",
|
|
17
18
|
"openapi-fetch": "^0.15.0"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
21
|
+
"prettier": "3.6.2",
|
|
20
22
|
"typescript": "^5.9.3"
|
|
21
23
|
},
|
|
22
24
|
"bin": {
|
|
@@ -32,6 +34,8 @@
|
|
|
32
34
|
"homepage": "https://github.com/SergioGlorias/broadcastCLI",
|
|
33
35
|
"scripts": {
|
|
34
36
|
"build": "tsc",
|
|
35
|
-
"start": "pnpm build && node ./dist/index.js"
|
|
37
|
+
"start": "pnpm build && node ./dist/index.js",
|
|
38
|
+
"format": "prettier --write ./src/**/*.ts ./package.json",
|
|
39
|
+
"lint": "prettier --check ./src/**/*.ts ./package.json"
|
|
36
40
|
}
|
|
37
41
|
}
|