libroadcast-cli 2.9.0 → 2.10.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 +7 -0
- package/dist/cmd/bulkIDsMulti.js +58 -0
- package/dist/utils/commandHandler.js +3 -0
- package/dist/utils/help.js +11 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -92,6 +92,11 @@ Commands:
|
|
|
92
92
|
Options:
|
|
93
93
|
--loop <intervalInSeconds> Continuously push the PGN file at the specified interval in seconds.
|
|
94
94
|
|
|
95
|
+
bulkIDsMulti <bulkID> <broadcastRoundIds...>
|
|
96
|
+
Sets Lichess Game IDs for multiple broadcast rounds using a Bulk Pairing ID.
|
|
97
|
+
The command will fetch game IDs from the specified Bulk Pairing and distribute them across the provided broadcast round IDs.
|
|
98
|
+
|
|
99
|
+
|
|
95
100
|
Examples:
|
|
96
101
|
# Login with your Lichess token (interactive)
|
|
97
102
|
$ login
|
|
@@ -121,6 +126,8 @@ Examples:
|
|
|
121
126
|
$ pushFilterID round456 https://example.com/games.pgn 12345 67890 --loop 120
|
|
122
127
|
# Convert Lichess Usernames source to Lichess Game IDs source for a broadcast round
|
|
123
128
|
$ convertNamesToID round456
|
|
129
|
+
# Set Lichess Game IDs from Bulk Parings for multiple rounds (roundId1, roundId2, roundId3) in a broadcast
|
|
130
|
+
$ bulkIDsMulti bulk123 roundId1 roundId2 roundId3
|
|
124
131
|
```
|
|
125
132
|
|
|
126
133
|
### Test Docker Build Locally
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { exit } from "node:process";
|
|
2
|
+
import { client, msgCommonErrorHelp, handleApiResponse, checkTokenScopes, sleep, } from "../utils/commandHandler.js";
|
|
3
|
+
import { getBroadcastRound } from "../utils/getInfoBroadcast.js";
|
|
4
|
+
import cl from "../utils/colors.js";
|
|
5
|
+
const setLichessGames = (round, games) => handleApiResponse(client.POST("/broadcast/round/{broadcastRoundId}/edit", {
|
|
6
|
+
params: {
|
|
7
|
+
path: { broadcastRoundId: round.id },
|
|
8
|
+
query: { patch: 1 },
|
|
9
|
+
},
|
|
10
|
+
body: {
|
|
11
|
+
syncSource: "ids",
|
|
12
|
+
syncIds: games,
|
|
13
|
+
},
|
|
14
|
+
}), `Successfully set games for round ${cl.whiteBold(round.id)} to ${cl.whiteBold(games)}.`, `Error setting games for round ${cl.whiteBold(round.id)}`);
|
|
15
|
+
const getBulkIds = (bulkID) => client
|
|
16
|
+
.GET("/api/bulk-pairing/{id}", {
|
|
17
|
+
params: { path: { id: bulkID } },
|
|
18
|
+
})
|
|
19
|
+
.then((response) => {
|
|
20
|
+
const data = response.data;
|
|
21
|
+
let ids = data?.games
|
|
22
|
+
.map((game) => game.id)
|
|
23
|
+
.filter((id) => typeof id === "string") || [];
|
|
24
|
+
return ids;
|
|
25
|
+
})
|
|
26
|
+
.catch((error) => {
|
|
27
|
+
console.error(cl.red(`Error fetching bulk pairing data: ${error.message}`));
|
|
28
|
+
return [];
|
|
29
|
+
});
|
|
30
|
+
const splitIdsIntoGroups = (broadcastsIds, gameIds) => gameIds.reduce((groups, id, index) => {
|
|
31
|
+
groups[index % broadcastsIds.length].push(id);
|
|
32
|
+
return groups;
|
|
33
|
+
}, broadcastsIds.map(() => []));
|
|
34
|
+
export const bulkIDsMultiCommand = async (args) => {
|
|
35
|
+
await checkTokenScopes();
|
|
36
|
+
const bulkID = args.shift();
|
|
37
|
+
const broadcastsIds = args;
|
|
38
|
+
if (!bulkID || !broadcastsIds) {
|
|
39
|
+
msgCommonErrorHelp("Broadcast ID and rounds IDs are required.");
|
|
40
|
+
exit(1);
|
|
41
|
+
}
|
|
42
|
+
const gameIds = await getBulkIds(bulkID);
|
|
43
|
+
if (gameIds.length === 0) {
|
|
44
|
+
console.error(cl.red(`No game IDs found for bulk ID ${cl.whiteBold(bulkID)}.`));
|
|
45
|
+
exit(1);
|
|
46
|
+
}
|
|
47
|
+
const groupedIds = splitIdsIntoGroups(broadcastsIds, gameIds);
|
|
48
|
+
for (let [index, group] of groupedIds.entries()) {
|
|
49
|
+
const roundId = broadcastsIds[index];
|
|
50
|
+
const round = await getBroadcastRound(roundId);
|
|
51
|
+
if (!round) {
|
|
52
|
+
console.error(cl.red(`Broadcast round with ID ${cl.whiteBold(roundId)} not found or has no rounds.`));
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
await setLichessGames(round, group.join(" "));
|
|
56
|
+
await sleep(500);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -18,6 +18,7 @@ import { loginCommand } from "../cmd/login.js";
|
|
|
18
18
|
import { getStoredCredentials } from "./credentials.js";
|
|
19
19
|
import { convertNamesToIDCommand } from "../cmd/convertNamesToID.js";
|
|
20
20
|
import { pushReorderCommand } from "../cmd/pushReorder.js";
|
|
21
|
+
import { bulkIDsMultiCommand } from "../cmd/bulkIDsMulti.js";
|
|
21
22
|
const getToken = () => {
|
|
22
23
|
const stored = getStoredCredentials();
|
|
23
24
|
const envToken = process.env.LICHESS_TOKEN;
|
|
@@ -49,6 +50,7 @@ export var Command;
|
|
|
49
50
|
Command["PushFilterID"] = "pushFilterID";
|
|
50
51
|
Command["ConvertNamesToID"] = "convertNamesToID";
|
|
51
52
|
Command["PushReorder"] = "pushReorder";
|
|
53
|
+
Command["BulkIDsMulti"] = "bulkIDsMulti";
|
|
52
54
|
})(Command || (Command = {}));
|
|
53
55
|
export const commands = new Map([
|
|
54
56
|
[Command.Login, loginCommand],
|
|
@@ -64,6 +66,7 @@ export const commands = new Map([
|
|
|
64
66
|
[Command.PushFilterID, pushFilterIDCommand],
|
|
65
67
|
[Command.ConvertNamesToID, convertNamesToIDCommand],
|
|
66
68
|
[Command.PushReorder, pushReorderCommand],
|
|
69
|
+
[Command.BulkIDsMulti, bulkIDsMultiCommand],
|
|
67
70
|
]);
|
|
68
71
|
export const client = createClient({
|
|
69
72
|
baseUrl: LICHESS_DOMAIN,
|
package/dist/utils/help.js
CHANGED
|
@@ -94,6 +94,11 @@ const helpPushReorder = [
|
|
|
94
94
|
` ${cl.bold("Options:")}`,
|
|
95
95
|
` --loop <intervalInSeconds> ${cl.gray("Continuously push the PGN file at the specified interval in seconds.")}`,
|
|
96
96
|
].join("\n");
|
|
97
|
+
const helpBulkIDsMulti = [
|
|
98
|
+
` ${cl.underItalic("bulkIDsMulti <bulkID> <broadcastRoundIds...>")}`,
|
|
99
|
+
` ${cl.gray("Sets Lichess Game IDs for multiple broadcast rounds using a Bulk Pairing ID.")}`,
|
|
100
|
+
` ${cl.gray("The command will fetch game IDs from the specified Bulk Pairing and distribute them across the provided broadcast round IDs.")}`,
|
|
101
|
+
].join("\n");
|
|
97
102
|
const msg = [
|
|
98
103
|
`${cl.boldYellow("Usage:")} ${cl.underItalic("<command> [options]")}`,
|
|
99
104
|
``,
|
|
@@ -125,6 +130,9 @@ const msg = [
|
|
|
125
130
|
``,
|
|
126
131
|
helpPushReorder,
|
|
127
132
|
``,
|
|
133
|
+
helpBulkIDsMulti,
|
|
134
|
+
``,
|
|
135
|
+
``,
|
|
128
136
|
`${cl.boldYellow("Examples:")}`,
|
|
129
137
|
` ${cl.gray("# Login with your Lichess token (interactive)")}`,
|
|
130
138
|
` $ ${cl.underItalic("login")}`,
|
|
@@ -154,6 +162,8 @@ const msg = [
|
|
|
154
162
|
` $ ${cl.underItalic("pushFilterID")} ${cl.italic("round456 https://example.com/games.pgn 12345 67890 --loop 120")}`,
|
|
155
163
|
` ${cl.gray("# Convert Lichess Usernames source to Lichess Game IDs source for a broadcast round")}`,
|
|
156
164
|
` $ ${cl.underItalic("convertNamesToID")} ${cl.italic("round456")}`,
|
|
165
|
+
` ${cl.gray("# Set Lichess Game IDs from Bulk Parings for multiple rounds (roundId1, roundId2, roundId3) in a broadcast")}`,
|
|
166
|
+
` $ ${cl.underItalic("bulkIDsMulti")} ${cl.italic("bulk123 roundId1 roundId2 roundId3")}`,
|
|
157
167
|
];
|
|
158
168
|
export const showHelp = (cmd) => {
|
|
159
169
|
const ranges = {
|
|
@@ -170,6 +180,7 @@ export const showHelp = (cmd) => {
|
|
|
170
180
|
[Command.PushFilterID]: helpPushFilterID,
|
|
171
181
|
[Command.ConvertNamesToID]: helpConvertNamesToID,
|
|
172
182
|
[Command.PushReorder]: helpPushReorder,
|
|
183
|
+
[Command.BulkIDsMulti]: helpBulkIDsMulti,
|
|
173
184
|
};
|
|
174
185
|
const range = cmd ? ranges[cmd] : undefined;
|
|
175
186
|
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.10.0",
|
|
4
4
|
"description": "CLI to help with broadcast maintenance on Lichess",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@lichess-org/types": "^2.0.109",
|
|
16
|
-
"@types/node": "~24.
|
|
16
|
+
"@types/node": "~24.11.0",
|
|
17
17
|
"chessops": "^0.15.0",
|
|
18
18
|
"ms": "3.0.0-canary.202508261828",
|
|
19
19
|
"openapi-fetch": "^0.17.0"
|