libroadcast-cli 2.0.0 → 2.1.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 +12 -3
- package/dist/cmd/login.js +0 -1
- package/dist/cmd/score.js +69 -0
- package/dist/utils/commandHandler.js +3 -0
- package/dist/utils/help.js +16 -2
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -70,6 +70,12 @@ 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
|
+
|
|
73
79
|
|
|
74
80
|
Examples:
|
|
75
81
|
# Login with your Lichess token (interactive)
|
|
@@ -82,13 +88,16 @@ Examples:
|
|
|
82
88
|
$ delay bcast123 300 --onlyDelay
|
|
83
89
|
# Set source PGN URL with round and slice filters
|
|
84
90
|
$ setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"
|
|
85
|
-
|
|
91
|
+
# Set source PGN URLs for multiple games per round
|
|
86
92
|
$ setPGNMulti bcast123 https://example.com/pgns/round-{r}/game-{g}.pgn 12 --withFilter --onlyGames "1-5,7,9-12"
|
|
87
93
|
# Set Lichess games for a broadcast round
|
|
88
94
|
$ setLichessGames round456 gameId1 gameId2 gameId3
|
|
89
95
|
# Fix schedule of rounds 1 to 4 and all rounds after 8 by adding 15 minutes
|
|
90
96
|
$ fixSchedule bcast123 15m --rounds 1-4,8+
|
|
91
|
-
|
|
97
|
+
# Set startsAfterPrevious to true for all rounds in a broadcast
|
|
92
98
|
$ startsPrevious bcast123 true
|
|
93
|
-
|
|
99
|
+
# Set polling period to 10 seconds for all rounds in a broadcast
|
|
100
|
+
$ period bcast123 10
|
|
101
|
+
# Set custom scoring for all rounds in a broadcast
|
|
102
|
+
$ score bcast123 1.0 0.5 1.0 0.5
|
|
94
103
|
```
|
package/dist/cmd/login.js
CHANGED
|
@@ -85,7 +85,6 @@ const loginCommand = async (args) => {
|
|
|
85
85
|
});
|
|
86
86
|
console.log("");
|
|
87
87
|
console.log(colors_1.default.green("✓ Credentials saved successfully! You can now use the CLI without setting environment variables."));
|
|
88
|
-
console.log(colors_1.default.blue("Note: Environment variables will always take precedence over saved credentials."));
|
|
89
88
|
}
|
|
90
89
|
catch (error) {
|
|
91
90
|
console.error(colors_1.default.red("Error during login:"), error);
|
|
@@ -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,7 @@ 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");
|
|
17
18
|
const login_1 = require("../cmd/login");
|
|
18
19
|
const credentials_1 = require("./credentials");
|
|
19
20
|
const getToken = () => {
|
|
@@ -40,6 +41,7 @@ var Command;
|
|
|
40
41
|
Command["FixSchedule"] = "fixSchedule";
|
|
41
42
|
Command["StartsPrevious"] = "startsPrevious";
|
|
42
43
|
Command["Period"] = "period";
|
|
44
|
+
Command["Score"] = "score";
|
|
43
45
|
})(Command || (exports.Command = Command = {}));
|
|
44
46
|
exports.commands = new Map([
|
|
45
47
|
[Command.Login, login_1.loginCommand],
|
|
@@ -50,6 +52,7 @@ exports.commands = new Map([
|
|
|
50
52
|
[Command.FixSchedule, fixSchedule_1.fixScheduleCommand],
|
|
51
53
|
[Command.StartsPrevious, startsPrevious_1.startsPreviousCommand],
|
|
52
54
|
[Command.Period, period_1.periodCommand],
|
|
55
|
+
[Command.Score, score_1.scoreCommand],
|
|
53
56
|
]);
|
|
54
57
|
exports.client = (0, openapi_fetch_1.default)({
|
|
55
58
|
baseUrl: LICHESS_DOMAIN,
|
package/dist/utils/help.js
CHANGED
|
@@ -67,6 +67,13 @@ 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");
|
|
70
77
|
const msg = [
|
|
71
78
|
`${colors_1.default.boldYellow("Usage:")} ${colors_1.default.underItalic("<command> [options]")}`,
|
|
72
79
|
``,
|
|
@@ -88,6 +95,8 @@ const msg = [
|
|
|
88
95
|
``,
|
|
89
96
|
helpSetPeriod,
|
|
90
97
|
``,
|
|
98
|
+
helpScore,
|
|
99
|
+
``,
|
|
91
100
|
``,
|
|
92
101
|
`${colors_1.default.boldYellow("Examples:")}`,
|
|
93
102
|
` ${colors_1.default.gray("# Login with your Lichess token (interactive)")}`,
|
|
@@ -100,14 +109,18 @@ const msg = [
|
|
|
100
109
|
` $ ${colors_1.default.underItalic("delay")} ${colors_1.default.italic("bcast123 300 --onlyDelay")}`,
|
|
101
110
|
` ${colors_1.default.gray("# Set source PGN URL with round and slice filters")}`,
|
|
102
111
|
` $ ${colors_1.default.underItalic("setPGN")} ${colors_1.default.italic('bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"')}`,
|
|
103
|
-
`
|
|
112
|
+
` ${colors_1.default.gray("# Set source PGN URLs for multiple games per round")}`,
|
|
104
113
|
` $ ${colors_1.default.underItalic("setPGNMulti")} ${colors_1.default.italic('bcast123 https://example.com/pgns/round-{r}/game-{g}.pgn 12 --withFilter --onlyGames "1-5,7,9-12"')}`,
|
|
105
114
|
` ${colors_1.default.gray("# Set Lichess games for a broadcast round")}`,
|
|
106
115
|
` $ ${colors_1.default.underItalic("setLichessGames")} ${colors_1.default.italic("round456 gameId1 gameId2 gameId3")}`,
|
|
107
116
|
` ${colors_1.default.gray("# Fix schedule of rounds 1 to 4 and all rounds after 8 by adding 15 minutes")}`,
|
|
108
117
|
` $ ${colors_1.default.underItalic("fixSchedule")} ${colors_1.default.italic("bcast123 15m --rounds 1-4,8+")}`,
|
|
109
|
-
`
|
|
118
|
+
` ${colors_1.default.gray("# Set startsAfterPrevious to true for all rounds in a broadcast")}`,
|
|
110
119
|
` $ ${colors_1.default.underItalic("startsPrevious")} ${colors_1.default.italic("bcast123 true")}`,
|
|
120
|
+
` ${colors_1.default.gray("# Set polling period to 10 seconds for all rounds in a broadcast")}`,
|
|
121
|
+
` $ ${colors_1.default.underItalic("period")} ${colors_1.default.italic("bcast123 10")}`,
|
|
122
|
+
` ${colors_1.default.gray("# Set custom scoring for all rounds in a broadcast")}`,
|
|
123
|
+
` $ ${colors_1.default.underItalic("score")} ${colors_1.default.italic("bcast123 1.0 0.5 1.0 0.5")}`,
|
|
111
124
|
];
|
|
112
125
|
const showHelp = (cmd) => {
|
|
113
126
|
const ranges = {
|
|
@@ -119,6 +132,7 @@ const showHelp = (cmd) => {
|
|
|
119
132
|
[commandHandler_1.Command.FixSchedule]: helpFixSchedule,
|
|
120
133
|
[commandHandler_1.Command.StartsPrevious]: helpStartsPrevious,
|
|
121
134
|
[commandHandler_1.Command.Period]: helpSetPeriod,
|
|
135
|
+
[commandHandler_1.Command.Score]: helpScore,
|
|
122
136
|
};
|
|
123
137
|
const range = cmd ? ranges[cmd] : undefined;
|
|
124
138
|
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.
|
|
3
|
+
"version": "2.1.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
|
},
|