libroadcast-cli 2.6.0 → 2.7.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.
@@ -4,7 +4,7 @@ import { parsePgn, makePgn } from "chessops/pgn";
4
4
  import { getBroadcastRound } from "../utils/getInfoBroadcast.js";
5
5
  import cl from "../utils/colors.js";
6
6
  import { loopChecker, pushPGN, readPGNFromURL } from "../utils/pushTools.js";
7
- const filterPgnByIds = (pgn, filterIds, firstOngoing) => {
7
+ const filterPgnByIds = (pgn, filterIds) => {
8
8
  const parsed = parsePgn(pgn);
9
9
  let filteredGames = parsed.filter((game) => {
10
10
  const whiteFideId = game.headers.get("WhiteFideId");
@@ -26,21 +26,10 @@ const filterPgnByIds = (pgn, filterIds, firstOngoing) => {
26
26
  filterIds.includes(parseInt(blackFideId || "", 10)));
27
27
  }
28
28
  });
29
- if (firstOngoing) {
30
- const ongoingGames = filteredGames.filter((game) => {
31
- const result = game.headers.get("Result");
32
- return !result || result === "*";
33
- });
34
- const gamesFinished = filteredGames.filter((game) => {
35
- const result = game.headers.get("Result");
36
- return result && result !== "*";
37
- });
38
- filteredGames = [...ongoingGames, ...gamesFinished];
39
- }
40
29
  return filteredGames.map((game) => makePgn(game)).join("\n\n");
41
30
  };
42
31
  let lastPGN = "";
43
- const loop = async (roundInfo, pgnPath, loopTimer, filterIds, firstOngoing) => {
32
+ const loop = async (roundInfo, pgnPath, loopTimer, filterIds) => {
44
33
  while (true) {
45
34
  const pgnContent = await readPGNFromURL(pgnPath);
46
35
  if (!pgnContent) {
@@ -48,7 +37,7 @@ const loop = async (roundInfo, pgnPath, loopTimer, filterIds, firstOngoing) => {
48
37
  await sleep(loopTimer * 1000);
49
38
  continue;
50
39
  }
51
- const filteredPgn = filterPgnByIds(pgnContent, filterIds, firstOngoing);
40
+ const filteredPgn = filterPgnByIds(pgnContent, filterIds);
52
41
  if (filteredPgn && filteredPgn !== lastPGN) {
53
42
  await pushPGN(roundInfo, filteredPgn);
54
43
  lastPGN = filteredPgn;
@@ -72,12 +61,11 @@ export const pushFilterIDCommand = async (args) => {
72
61
  console.error(cl.red("Round not found."));
73
62
  exit(1);
74
63
  }
75
- const firstOngoing = args.includes("--firstOngoing");
76
64
  const loopTimer = loopChecker(args);
77
65
  if (loopTimer) {
78
66
  console.log(cl.green(`Starting loop to push PGN every ${cl.whiteBold(loopTimer.toString())} seconds...`));
79
67
  console.log(cl.blue("Press Ctrl+C to stop."));
80
- await loop(roundInfo, pgnPath, loopTimer, filterIds, firstOngoing);
68
+ await loop(roundInfo, pgnPath, loopTimer, filterIds);
81
69
  }
82
70
  else {
83
71
  const pgnContent = await readPGNFromURL(pgnPath);
@@ -85,7 +73,7 @@ export const pushFilterIDCommand = async (args) => {
85
73
  console.error(cl.red(`Failed to read PGN content.`));
86
74
  exit(1);
87
75
  }
88
- const filteredPgn = filterPgnByIds(pgnContent, filterIds, firstOngoing);
76
+ const filteredPgn = filterPgnByIds(pgnContent, filterIds);
89
77
  if (filteredPgn)
90
78
  await pushPGN(roundInfo, filteredPgn);
91
79
  }
@@ -18,7 +18,8 @@ import { loginCommand } from "../cmd/login.js";
18
18
  import { getStoredCredentials } from "./credentials.js";
19
19
  const getToken = () => {
20
20
  const stored = getStoredCredentials();
21
- return stored?.lichessToken;
21
+ const envToken = process.env.LICHESS_TOKEN;
22
+ return envToken || stored?.lichessToken;
22
23
  };
23
24
  const getDomain = () => {
24
25
  const stored = getStoredCredentials();
@@ -76,12 +76,11 @@ const helpPush = [
76
76
  ` --loop <intervalInSeconds> ${cl.gray("Continuously push the PGN file at the specified interval in seconds.")}`,
77
77
  ].join("\n");
78
78
  const helpPushFilterID = [
79
- ` ${cl.underItalic("pushFilterID <roundId> <PGNFromPathOrUrl> <FideIds...> [--loop <intervalInSeconds>] [--firstOngoing]")}`,
79
+ ` ${cl.underItalic("pushFilterID <roundId> <PGNFromPathOrUrl> <FideIds...> [--loop <intervalInSeconds>]")}`,
80
80
  ` ${cl.gray("Upload a PGN file from a local path or URL to the specified broadcast round, filtering games by FIDE ID.")}`,
81
81
  ` ${cl.bold("Note:")} ${cl.gray("The PGN file must be accessible from the provided path or URL.")}`,
82
82
  ` ${cl.bold("Options:")}`,
83
83
  ` --loop <intervalInSeconds> ${cl.gray("Continuously push the PGN file at the specified interval in seconds.")}`,
84
- ` --firstOngoing ${cl.gray("Push the first ongoing games in each round.")}`,
85
84
  ].join("\n");
86
85
  const msg = [
87
86
  `${cl.boldYellow("Usage:")} ${cl.underItalic("<command> [options]")}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libroadcast-cli",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "CLI to help with broadcast maintenance on Lichess",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [