diff --git a/README.md b/README.md index 9f8a666..8b714cd 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Options: ("vs", "coop") --with-summary Include summary in the output --help Show this help message and exit + --nxapi-presence Extends monitoring mode to use Nintendo Switch presence from nxapi ``` 3. If it's your first time running this, follow the instructions to login to diff --git a/s3si.ts b/s3si.ts index 8b941ad..7a68412 100644 --- a/s3si.ts +++ b/s3si.ts @@ -4,7 +4,13 @@ import { flags } from "./deps.ts"; const parseArgs = (args: string[]) => { const parsed = flags.parse(args, { - string: ["profilePath", "exporter", "skipMode", "listMethod"], + string: [ + "profilePath", + "exporter", + "skipMode", + "listMethod", + "nxapiPresenceUrl", + ], boolean: ["help", "noProgress", "monitor", "withSummary"], alias: { "help": "h", @@ -15,6 +21,7 @@ const parseArgs = (args: string[]) => { "skipMode": ["s", "skip-mode"], "withSummary": "with-summary", "listMethod": "list-method", + "nxapiPresenceUrl": ["nxapi-presence"], }, }); return parsed; @@ -39,7 +46,8 @@ Options: --skip-mode , -s Skip mode (default: null) ("vs", "coop") --with-summary Include summary in the output - --help Show this help message and exit`, + --help Show this help message and exit + --nxapi-presence Extends monitoring mode to use Nintendo Switch presence from nxapi`, ); Deno.exit(0); } diff --git a/src/app.ts b/src/app.ts index 4e709be..70e49cb 100644 --- a/src/app.ts +++ b/src/app.ts @@ -10,6 +10,7 @@ import { delay, showError } from "./utils.ts"; import { GameFetcher } from "./GameFetcher.ts"; import { DEFAULT_ENV, Env } from "./env.ts"; import { SplashcatExporter } from "./exporters/splashcat.ts"; +import { SPLATOON3_TITLE_ID } from "./constant.ts"; export type Opts = { profilePath: string; @@ -22,6 +23,7 @@ export type Opts = { cache?: Cache; stateBackend?: StateBackend; env: Env; + nxapiPresenceUrl?: string; }; export const DEFAULT_OPTS: Opts = { @@ -163,6 +165,7 @@ function progress({ total, currentUrl, done }: StepProgress): Progress { export class App { profile: Profile; env: Env; + splatoon3PreviouslyActive = false; constructor(public opts: Opts) { const stateBackend = opts.stateBackend ?? @@ -419,6 +422,30 @@ export class App { } } } + async monitorWithNxapi() { + this.env.logger.debug("Monitoring with nxapi presence"); + await this.exportOnce(); + + while (true) { + await this.countDown(this.profile.state.monitorInterval); + const nxapiResponse = await fetch(this.opts.nxapiPresenceUrl!); + const nxapiData = await nxapiResponse.json(); + const isSplatoon3Active = nxapiData.title?.id === SPLATOON3_TITLE_ID; + if (isSplatoon3Active || this.splatoon3PreviouslyActive) { + this.env.logger.log("Splatoon 3 is active, exporting data"); + await this.exportOnce(); + } + if (isSplatoon3Active !== this.splatoon3PreviouslyActive) { + this.env.logger.debug( + "Splatoon 3 status has changed from", + this.splatoon3PreviouslyActive, + "to", + isSplatoon3Active, + ); + } + this.splatoon3PreviouslyActive = isSplatoon3Active; + } + } async monitor() { while (true) { await this.exportOnce(); @@ -456,7 +483,9 @@ export class App { }); } - if (this.opts.monitor) { + if (this.opts.nxapiPresenceUrl) { + await this.monitorWithNxapi(); + } else if (this.opts.monitor) { await this.monitor(); } else { await this.exportOnce(); diff --git a/src/constant.ts b/src/constant.ts index ad0ec0a..ea945ec 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -116,3 +116,5 @@ export const SPLATNET3_STATINK_MAP: { 2: "high", }, }; + +export const SPLATOON3_TITLE_ID = "0100c2500fc20000";