libroadcast-cli 2.0.1 → 2.2.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 +20 -3
- package/dist/cmd/push.js +102 -0
- package/dist/cmd/score.js +69 -0
- package/dist/utils/commandHandler.js +6 -0
- package/dist/utils/help.js +26 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -70,6 +70,18 @@ Commands:
|
|
|
70
70
|
Options:
|
|
71
71
|
--rounds <roundsToFix> Specify which rounds to fix using formats like '1-4', '8+', '3,5,7', etc.
|
|
72
72
|
|
|
73
|
+
score <broadcastId> <whiteWin> <whiteDraw> <blackWin> <blackDraw> [--rounds <roundsToFix>]
|
|
74
|
+
Sets the custom scoring for all rounds in the specified broadcast.
|
|
75
|
+
Note: Scores must be numbers between 0 and 10.
|
|
76
|
+
Options:
|
|
77
|
+
--rounds <roundsToFix> Specify which rounds to fix using formats like '1-4', '8+', '3,5,7', etc.
|
|
78
|
+
|
|
79
|
+
push <roundId> <PGNFromPathOrUrl> [--loop <intervalInSeconds>]
|
|
80
|
+
Upload a PGN file from a local path or URL to the specified broadcast round.
|
|
81
|
+
Note: The PGN file must be accessible from the provided path or URL.
|
|
82
|
+
Options:
|
|
83
|
+
--loop <intervalInSeconds> Continuously push the PGN file at the specified interval in seconds.
|
|
84
|
+
|
|
73
85
|
|
|
74
86
|
Examples:
|
|
75
87
|
# Login with your Lichess token (interactive)
|
|
@@ -82,13 +94,18 @@ Examples:
|
|
|
82
94
|
$ delay bcast123 300 --onlyDelay
|
|
83
95
|
# Set source PGN URL with round and slice filters
|
|
84
96
|
$ setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"
|
|
85
|
-
|
|
97
|
+
# Set source PGN URLs for multiple games per round
|
|
86
98
|
$ setPGNMulti bcast123 https://example.com/pgns/round-{r}/game-{g}.pgn 12 --withFilter --onlyGames "1-5,7,9-12"
|
|
87
99
|
# Set Lichess games for a broadcast round
|
|
88
100
|
$ setLichessGames round456 gameId1 gameId2 gameId3
|
|
89
101
|
# Fix schedule of rounds 1 to 4 and all rounds after 8 by adding 15 minutes
|
|
90
102
|
$ fixSchedule bcast123 15m --rounds 1-4,8+
|
|
91
|
-
|
|
103
|
+
# Set startsAfterPrevious to true for all rounds in a broadcast
|
|
92
104
|
$ startsPrevious bcast123 true
|
|
93
|
-
|
|
105
|
+
# Set polling period to 10 seconds for all rounds in a broadcast
|
|
106
|
+
$ period bcast123 10
|
|
107
|
+
# Set custom scoring for all rounds in a broadcast
|
|
108
|
+
$ score bcast123 1.0 0.5 1.0 0.5
|
|
109
|
+
# Push a PGN file in loop mode every 60 seconds
|
|
110
|
+
$ push round456 /path/to/localfile.pgn --loop 60
|
|
94
111
|
```
|
package/dist/cmd/push.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
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.pushCommand = void 0;
|
|
7
|
+
const node_process_1 = require("node:process");
|
|
8
|
+
const promises_1 = require("node:fs/promises");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const commandHandler_1 = require("../utils/commandHandler");
|
|
11
|
+
const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
|
|
12
|
+
const colors_1 = __importDefault(require("../utils/colors"));
|
|
13
|
+
const pushPGN = async (round, pgn) => {
|
|
14
|
+
try {
|
|
15
|
+
const res = await commandHandler_1.client
|
|
16
|
+
.POST("/api/broadcast/round/{broadcastRoundId}/push", {
|
|
17
|
+
params: {
|
|
18
|
+
path: { broadcastRoundId: round.id },
|
|
19
|
+
},
|
|
20
|
+
body: pgn,
|
|
21
|
+
bodySerializer: (body) => body,
|
|
22
|
+
})
|
|
23
|
+
.then((response) => response.data);
|
|
24
|
+
console.log(colors_1.default.green(`✓ Successfully pushed PGN for round ${colors_1.default.whiteBold(round.id)}.`));
|
|
25
|
+
console.table(res?.games.map((game, i) => {
|
|
26
|
+
return {
|
|
27
|
+
"Game #": i + 1,
|
|
28
|
+
"White Player": game.tags["White"] || "Unknown",
|
|
29
|
+
"Black Player": game.tags["Black"] || "Unknown",
|
|
30
|
+
Result: game.tags["Result"] || "Unknown",
|
|
31
|
+
"Ply Count": game.moves || "Unknown",
|
|
32
|
+
Error: game.error || "None",
|
|
33
|
+
};
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error(colors_1.default.red(`Error pushing PGN for round ${colors_1.default.whiteBold(round.id)}:`), error);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const readPGNFromURL = async (pgnURL) => {
|
|
41
|
+
if (pgnURL.startsWith("http://") || pgnURL.startsWith("https://")) {
|
|
42
|
+
const response = await fetch(pgnURL);
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
console.error(colors_1.default.red(`Failed to fetch PGN from URL: ${response.statusText}`));
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const pgnText = await response.text();
|
|
48
|
+
return pgnText;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const resolvedPath = node_path_1.default.resolve(pgnURL);
|
|
52
|
+
const stats = await (0, promises_1.readFile)(resolvedPath, { encoding: "utf-8" }).catch((err) => {
|
|
53
|
+
console.error(colors_1.default.red(`Failed to read PGN file: ${err.message}`));
|
|
54
|
+
return undefined;
|
|
55
|
+
});
|
|
56
|
+
if (!stats)
|
|
57
|
+
return undefined;
|
|
58
|
+
return stats.toString();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const loop = async (roundInfo, pgnPath, loopTimer) => {
|
|
62
|
+
while (true) {
|
|
63
|
+
const pgnContent = await readPGNFromURL(pgnPath);
|
|
64
|
+
if (pgnContent)
|
|
65
|
+
await pushPGN(roundInfo, pgnContent);
|
|
66
|
+
await (0, commandHandler_1.sleep)(loopTimer * 1000);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const pushCommand = async (args) => {
|
|
70
|
+
await (0, commandHandler_1.checkTokenScopes)();
|
|
71
|
+
const [roundId, pgnPath] = args.slice(0, 2);
|
|
72
|
+
if (!roundId || !pgnPath) {
|
|
73
|
+
(0, commandHandler_1.msgCommonErrorHelp)("Round ID and PGN are required.");
|
|
74
|
+
(0, node_process_1.exit)(1);
|
|
75
|
+
}
|
|
76
|
+
const roundInfo = await (0, getInfoBroadcast_1.getBroadcastRound)(roundId);
|
|
77
|
+
if (!roundInfo) {
|
|
78
|
+
console.error(colors_1.default.red("Round not found."));
|
|
79
|
+
(0, node_process_1.exit)(1);
|
|
80
|
+
}
|
|
81
|
+
const loopArgIndex = args.findIndex((arg) => arg === "--loop");
|
|
82
|
+
let loopTimer = undefined;
|
|
83
|
+
if (loopArgIndex !== -1 && loopArgIndex + 1 < args.length) {
|
|
84
|
+
const loopTimerStr = args[loopArgIndex + 1];
|
|
85
|
+
loopTimer = parseInt(loopTimerStr, 10);
|
|
86
|
+
if (isNaN(loopTimer) || loopTimer <= 0) {
|
|
87
|
+
console.error(colors_1.default.red("Loop timer must be a positive integer."));
|
|
88
|
+
(0, node_process_1.exit)(1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (loopTimer) {
|
|
92
|
+
console.log(colors_1.default.green(`Starting loop to push PGN every ${colors_1.default.whiteBold(loopTimer.toString())} seconds...`));
|
|
93
|
+
console.log(colors_1.default.blue("Press Ctrl+C to stop."));
|
|
94
|
+
await loop(roundInfo, pgnPath, loopTimer);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const pgnContent = await readPGNFromURL(pgnPath);
|
|
98
|
+
if (pgnContent)
|
|
99
|
+
await pushPGN(roundInfo, pgnContent);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.pushCommand = pushCommand;
|
|
@@ -0,0 +1,69 @@
|
|
|
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.scoreCommand = 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 setScoreRounds = async (rounds, blackWin, blackDraw, whiteWin, whiteDraw, roundsToFix) => {
|
|
12
|
+
let filteredRounds = rounds.filter((_, i) => !roundsToFix?.length || roundsToFix.includes(i + 1));
|
|
13
|
+
if (filteredRounds.length === 0)
|
|
14
|
+
filteredRounds = rounds;
|
|
15
|
+
for (const round of filteredRounds) {
|
|
16
|
+
await (0, commandHandler_1.handleApiResponse)(commandHandler_1.client.POST("/broadcast/round/{broadcastRoundId}/edit", {
|
|
17
|
+
params: {
|
|
18
|
+
path: { broadcastRoundId: round.id },
|
|
19
|
+
query: { patch: 1 },
|
|
20
|
+
},
|
|
21
|
+
body: {
|
|
22
|
+
"customScoring.black.draw": blackDraw,
|
|
23
|
+
"customScoring.black.win": blackWin,
|
|
24
|
+
"customScoring.white.draw": whiteDraw,
|
|
25
|
+
"customScoring.white.win": whiteWin,
|
|
26
|
+
},
|
|
27
|
+
}), `Successfully set score for round ${colors_1.default.whiteBold(round.id)}: Black win=${colors_1.default.whiteBold(blackWin.toString())}, Black draw=${colors_1.default.whiteBold(blackDraw.toString())}, White win=${colors_1.default.whiteBold(whiteWin.toString())}, White draw=${colors_1.default.whiteBold(whiteDraw.toString())}.`, `Error setting score for round ${colors_1.default.whiteBold(round.id)}`);
|
|
28
|
+
await (0, commandHandler_1.sleep)(200);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const scoreCommand = async (args) => {
|
|
32
|
+
await (0, commandHandler_1.checkTokenScopes)();
|
|
33
|
+
const [broadcastId, whiteWinStr, whiteDrawStr, blackWinStr, blackDrawStr] = args.slice(0, 5);
|
|
34
|
+
if (!broadcastId ||
|
|
35
|
+
!whiteWinStr ||
|
|
36
|
+
!whiteDrawStr ||
|
|
37
|
+
!blackWinStr ||
|
|
38
|
+
!blackDrawStr) {
|
|
39
|
+
(0, commandHandler_1.msgCommonErrorHelp)("Broadcast ID, white win, white draw, black win, and black draw scores are required.");
|
|
40
|
+
(0, node_process_1.exit)(1);
|
|
41
|
+
}
|
|
42
|
+
const [whiteWin, whiteDraw, blackWin, blackDraw] = [
|
|
43
|
+
whiteWinStr,
|
|
44
|
+
whiteDrawStr,
|
|
45
|
+
blackWinStr,
|
|
46
|
+
blackDrawStr,
|
|
47
|
+
].map((scoreStr) => parseFloat(scoreStr));
|
|
48
|
+
if ([whiteWin, whiteDraw, blackWin, blackDraw].some(isNaN)) {
|
|
49
|
+
(0, commandHandler_1.msgCommonErrorHelp)("Scores for white win, white draw, black win, and black draw must be valid numbers.");
|
|
50
|
+
(0, node_process_1.exit)(1);
|
|
51
|
+
}
|
|
52
|
+
if ([whiteWin, whiteDraw, blackWin, blackDraw].some((score) => score < 0 || score > 10)) {
|
|
53
|
+
(0, commandHandler_1.msgCommonErrorHelp)("Scores for white win, white draw, black win, and black draw must be between 0 and 10.");
|
|
54
|
+
(0, node_process_1.exit)(1);
|
|
55
|
+
}
|
|
56
|
+
const roundsArgIndex = args.findIndex((arg) => arg === "--rounds");
|
|
57
|
+
let roundsToFix = undefined;
|
|
58
|
+
if (roundsArgIndex !== -1 && roundsArgIndex + 1 < args.length) {
|
|
59
|
+
const roundsArg = args[roundsArgIndex + 1];
|
|
60
|
+
roundsToFix = roundsArg ? (0, commandHandler_1.translateRoundsToFix)(roundsArg) : undefined;
|
|
61
|
+
}
|
|
62
|
+
const broadcast = await (0, getInfoBroadcast_1.getBroadcast)(broadcastId);
|
|
63
|
+
if (!broadcast?.rounds || broadcast.rounds.length === 0) {
|
|
64
|
+
console.error(colors_1.default.red("No rounds found for the specified broadcast."));
|
|
65
|
+
(0, node_process_1.exit)(1);
|
|
66
|
+
}
|
|
67
|
+
await setScoreRounds(broadcast.rounds, blackWin, blackDraw, whiteWin, whiteDraw, roundsToFix);
|
|
68
|
+
};
|
|
69
|
+
exports.scoreCommand = scoreCommand;
|
|
@@ -14,6 +14,8 @@ const setLichessGames_1 = require("../cmd/setLichessGames");
|
|
|
14
14
|
const fixSchedule_1 = require("../cmd/fixSchedule");
|
|
15
15
|
const startsPrevious_1 = require("../cmd/startsPrevious");
|
|
16
16
|
const period_1 = require("../cmd/period");
|
|
17
|
+
const score_1 = require("../cmd/score");
|
|
18
|
+
const push_1 = require("../cmd/push");
|
|
17
19
|
const login_1 = require("../cmd/login");
|
|
18
20
|
const credentials_1 = require("./credentials");
|
|
19
21
|
const getToken = () => {
|
|
@@ -40,6 +42,8 @@ var Command;
|
|
|
40
42
|
Command["FixSchedule"] = "fixSchedule";
|
|
41
43
|
Command["StartsPrevious"] = "startsPrevious";
|
|
42
44
|
Command["Period"] = "period";
|
|
45
|
+
Command["Score"] = "score";
|
|
46
|
+
Command["Push"] = "push";
|
|
43
47
|
})(Command || (exports.Command = Command = {}));
|
|
44
48
|
exports.commands = new Map([
|
|
45
49
|
[Command.Login, login_1.loginCommand],
|
|
@@ -50,6 +54,8 @@ exports.commands = new Map([
|
|
|
50
54
|
[Command.FixSchedule, fixSchedule_1.fixScheduleCommand],
|
|
51
55
|
[Command.StartsPrevious, startsPrevious_1.startsPreviousCommand],
|
|
52
56
|
[Command.Period, period_1.periodCommand],
|
|
57
|
+
[Command.Score, score_1.scoreCommand],
|
|
58
|
+
[Command.Push, push_1.pushCommand],
|
|
53
59
|
]);
|
|
54
60
|
exports.client = (0, openapi_fetch_1.default)({
|
|
55
61
|
baseUrl: LICHESS_DOMAIN,
|
package/dist/utils/help.js
CHANGED
|
@@ -67,6 +67,20 @@ const helpSetPeriod = [
|
|
|
67
67
|
` ${colors_1.default.bold("Options:")}`,
|
|
68
68
|
` --rounds <roundsToFix> ${colors_1.default.gray("Specify which rounds to fix using formats like '1-4', '8+', '3,5,7', etc.")}`,
|
|
69
69
|
].join("\n");
|
|
70
|
+
const helpScore = [
|
|
71
|
+
` ${colors_1.default.underItalic("score <broadcastId> <whiteWin> <whiteDraw> <blackWin> <blackDraw> [--rounds <roundsToFix>]")}`,
|
|
72
|
+
` ${colors_1.default.gray("Sets the custom scoring for all rounds in the specified broadcast.")}`,
|
|
73
|
+
` ${colors_1.default.bold("Note:")} ${colors_1.default.gray("Scores must be numbers between 0 and 10.")}`,
|
|
74
|
+
` ${colors_1.default.bold("Options:")}`,
|
|
75
|
+
` --rounds <roundsToFix> ${colors_1.default.gray("Specify which rounds to fix using formats like '1-4', '8+', '3,5,7', etc.")}`,
|
|
76
|
+
].join("\n");
|
|
77
|
+
const helpPush = [
|
|
78
|
+
` ${colors_1.default.underItalic("push <roundId> <PGNFromPathOrUrl> [--loop <intervalInSeconds>]")}`,
|
|
79
|
+
` ${colors_1.default.gray("Upload a PGN file from a local path or URL to the specified broadcast round.")}`,
|
|
80
|
+
` ${colors_1.default.bold("Note:")} ${colors_1.default.gray("The PGN file must be accessible from the provided path or URL.")}`,
|
|
81
|
+
` ${colors_1.default.bold("Options:")}`,
|
|
82
|
+
` --loop <intervalInSeconds> ${colors_1.default.gray("Continuously push the PGN file at the specified interval in seconds.")}`,
|
|
83
|
+
].join("\n");
|
|
70
84
|
const msg = [
|
|
71
85
|
`${colors_1.default.boldYellow("Usage:")} ${colors_1.default.underItalic("<command> [options]")}`,
|
|
72
86
|
``,
|
|
@@ -88,6 +102,10 @@ const msg = [
|
|
|
88
102
|
``,
|
|
89
103
|
helpSetPeriod,
|
|
90
104
|
``,
|
|
105
|
+
helpScore,
|
|
106
|
+
``,
|
|
107
|
+
helpPush,
|
|
108
|
+
``,
|
|
91
109
|
``,
|
|
92
110
|
`${colors_1.default.boldYellow("Examples:")}`,
|
|
93
111
|
` ${colors_1.default.gray("# Login with your Lichess token (interactive)")}`,
|
|
@@ -108,6 +126,12 @@ const msg = [
|
|
|
108
126
|
` $ ${colors_1.default.underItalic("fixSchedule")} ${colors_1.default.italic("bcast123 15m --rounds 1-4,8+")}`,
|
|
109
127
|
` ${colors_1.default.gray("# Set startsAfterPrevious to true for all rounds in a broadcast")}`,
|
|
110
128
|
` $ ${colors_1.default.underItalic("startsPrevious")} ${colors_1.default.italic("bcast123 true")}`,
|
|
129
|
+
` ${colors_1.default.gray("# Set polling period to 10 seconds for all rounds in a broadcast")}`,
|
|
130
|
+
` $ ${colors_1.default.underItalic("period")} ${colors_1.default.italic("bcast123 10")}`,
|
|
131
|
+
` ${colors_1.default.gray("# Set custom scoring for all rounds in a broadcast")}`,
|
|
132
|
+
` $ ${colors_1.default.underItalic("score")} ${colors_1.default.italic("bcast123 1.0 0.5 1.0 0.5")}`,
|
|
133
|
+
` ${colors_1.default.gray("# Push a PGN file in loop mode every 60 seconds")}`,
|
|
134
|
+
` $ ${colors_1.default.underItalic("push")} ${colors_1.default.italic("round456 /path/to/localfile.pgn --loop 60")}`,
|
|
111
135
|
];
|
|
112
136
|
const showHelp = (cmd) => {
|
|
113
137
|
const ranges = {
|
|
@@ -119,6 +143,8 @@ const showHelp = (cmd) => {
|
|
|
119
143
|
[commandHandler_1.Command.FixSchedule]: helpFixSchedule,
|
|
120
144
|
[commandHandler_1.Command.StartsPrevious]: helpStartsPrevious,
|
|
121
145
|
[commandHandler_1.Command.Period]: helpSetPeriod,
|
|
146
|
+
[commandHandler_1.Command.Score]: helpScore,
|
|
147
|
+
[commandHandler_1.Command.Push]: helpPush,
|
|
122
148
|
};
|
|
123
149
|
const range = cmd ? ranges[cmd] : undefined;
|
|
124
150
|
console.info(range ? range : msg.join("\n"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libroadcast-cli",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "CLI to help with broadcast maintenance on Lichess",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"type": "commonjs",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lichess-org/types": "^2.0.
|
|
16
|
-
"@types/node": "
|
|
15
|
+
"@lichess-org/types": "^2.0.109",
|
|
16
|
+
"@types/node": "~24.10.4",
|
|
17
17
|
"ms": "3.0.0-canary.202508261828",
|
|
18
18
|
"openapi-fetch": "^0.15.0"
|
|
19
19
|
},
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
"prettier": "3.7.4",
|
|
22
22
|
"typescript": "^5.9.3"
|
|
23
23
|
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=24.0.0"
|
|
26
|
+
},
|
|
24
27
|
"bin": {
|
|
25
28
|
"libroadcast": "./dist/index.js"
|
|
26
29
|
},
|