libroadcast-cli 1.5.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 +9 -1
- package/dist/cmd/fixSchedule.js +90 -0
- package/dist/index.js +7 -5
- package/dist/utils/commandHandler.js +3 -2
- package/dist/utils/help.js +32 -15
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -37,6 +37,12 @@ Commands:
|
|
|
37
37
|
Sets the games for the specified broadcast round using Lichess game IDs.
|
|
38
38
|
Note: Maximum of 64 game IDs can be provided.
|
|
39
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
|
+
|
|
40
46
|
|
|
41
47
|
Examples:
|
|
42
48
|
# Set a 5-minute delay without changing start time
|
|
@@ -44,5 +50,7 @@ Examples:
|
|
|
44
50
|
# Set source PGN URL with round and slice filters
|
|
45
51
|
$ setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"
|
|
46
52
|
# Set Lichess games for a broadcast round
|
|
47
|
-
$ setLichessGames round456 gameId1 gameId2 gameId3
|
|
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+
|
|
48
56
|
```
|
|
@@ -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;
|
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);
|
|
@@ -9,6 +9,7 @@ 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");
|
|
12
13
|
const colors_1 = __importDefault(require("./colors"));
|
|
13
14
|
exports.LICHESS_TOKEN = node_process_1.env.LICHESS_TOKEN;
|
|
14
15
|
const LICHESS_DOMAIN = node_process_1.env.LICHESS_DOMAIN || "https://lichess.org/";
|
|
@@ -16,15 +17,15 @@ exports.args = node_process_1.argv.slice(2);
|
|
|
16
17
|
var Command;
|
|
17
18
|
(function (Command) {
|
|
18
19
|
Command["Delay"] = "delay";
|
|
19
|
-
Command["SetLCC"] = "setLCC";
|
|
20
20
|
Command["SetPGN"] = "setPGN";
|
|
21
21
|
Command["SetLichessGames"] = "setLichessGames";
|
|
22
|
+
Command["FixSchedule"] = "fixSchedule";
|
|
22
23
|
})(Command || (exports.Command = Command = {}));
|
|
23
24
|
exports.commands = new Map([
|
|
24
25
|
[Command.Delay, delay_1.delayCommand],
|
|
25
|
-
[Command.SetLCC, setPGN_1.setPGNCommand],
|
|
26
26
|
[Command.SetPGN, setPGN_1.setPGNCommand],
|
|
27
27
|
[Command.SetLichessGames, setLichessGames_1.setLichessGamesCommand],
|
|
28
|
+
[Command.FixSchedule, fixSchedule_1.fixScheduleCommand],
|
|
28
29
|
]);
|
|
29
30
|
exports.client = (0, openapi_fetch_1.default)({
|
|
30
31
|
baseUrl: LICHESS_DOMAIN,
|
package/dist/utils/help.js
CHANGED
|
@@ -6,18 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.includeHelp = exports.showHelp = void 0;
|
|
7
7
|
const commandHandler_1 = require("./commandHandler");
|
|
8
8
|
const colors_1 = __importDefault(require("./colors"));
|
|
9
|
-
const
|
|
10
|
-
`${colors_1.default.boldYellow("Usage:")} ${colors_1.default.underItalic("<command> [options]")}`,
|
|
11
|
-
``,
|
|
12
|
-
``,
|
|
13
|
-
`${colors_1.default.boldYellow("Commands:")}`,
|
|
9
|
+
const helpDelay = [
|
|
14
10
|
` ${colors_1.default.underItalic("delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]")}`,
|
|
15
11
|
` ${colors_1.default.gray("Sets the delay for all rounds in the specified broadcast.")}`,
|
|
16
12
|
` ${colors_1.default.bold("Note:")} ${colors_1.default.gray("The delay is specified in seconds. (max 3600 seconds = 1 hour)")}`,
|
|
17
13
|
` ${colors_1.default.bold("Options:")}`,
|
|
18
14
|
` --onlyDelay ${colors_1.default.gray("Set only the delay without changing the start time.")}`,
|
|
19
15
|
` --noDelay ${colors_1.default.gray("Remove the delay from the rounds.")}`,
|
|
20
|
-
|
|
16
|
+
].join("\n");
|
|
17
|
+
const helpSetPGN = [
|
|
21
18
|
` ${colors_1.default.underItalic("setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]")}`,
|
|
22
19
|
` ${colors_1.default.gray("Sets the source PGN URL for all rounds in the specified broadcast.")}`,
|
|
23
20
|
` ${colors_1.default.italic("(optional)")} ${colors_1.default.gray('Use "{}" in the URL as a placeholder for the round number.')}`,
|
|
@@ -25,10 +22,31 @@ const msg = [
|
|
|
25
22
|
` ${colors_1.default.bold("Options:")}`,
|
|
26
23
|
` --withFilter ${colors_1.default.gray("Apply round number filtering based on round number.")}`,
|
|
27
24
|
` --slice <sliceFilter> ${colors_1.default.gray("Apply slice filtering using the provided filter string.")}`,
|
|
28
|
-
|
|
25
|
+
].join("\n");
|
|
26
|
+
const helpSetLichessGames = [
|
|
29
27
|
` ${colors_1.default.underItalic("setLichessGames <broadcastRoundId> <gameIds...>")}`,
|
|
30
28
|
` ${colors_1.default.gray("Sets the games for the specified broadcast round using Lichess game IDs.")}`,
|
|
31
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");
|
|
38
|
+
const msg = [
|
|
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,
|
|
32
50
|
``,
|
|
33
51
|
``,
|
|
34
52
|
`${colors_1.default.boldYellow("Examples:")}`,
|
|
@@ -38,19 +56,18 @@ const msg = [
|
|
|
38
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"')}`,
|
|
39
57
|
` ${colors_1.default.gray("# Set Lichess games for a broadcast round")}`,
|
|
40
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+")}`,
|
|
41
61
|
];
|
|
42
62
|
const showHelp = (cmd) => {
|
|
43
63
|
const ranges = {
|
|
44
|
-
[commandHandler_1.Command.Delay]:
|
|
45
|
-
[commandHandler_1.Command.SetPGN]:
|
|
46
|
-
[commandHandler_1.Command.
|
|
47
|
-
[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,
|
|
48
68
|
};
|
|
49
69
|
const range = cmd ? ranges[cmd] : undefined;
|
|
50
|
-
|
|
51
|
-
console.warn("Warning: 'setLCC' command was removed. Use 'setPGN' command instead.");
|
|
52
|
-
}
|
|
53
|
-
console.info(range ? msg.slice(...range).join("\n") : msg.join("\n"));
|
|
70
|
+
console.info(range ? range : msg.join("\n"));
|
|
54
71
|
};
|
|
55
72
|
exports.showHelp = showHelp;
|
|
56
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,6 +14,7 @@
|
|
|
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": {
|