use s3si.ts fetcher and send a user agent

nxapi-presence
Rosalina 2024-01-14 18:11:03 -05:00
parent 6f396d012c
commit c336f0e7b7
No known key found for this signature in database
1 changed files with 8 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import { delay, showError } from "./utils.ts";
import { GameFetcher } from "./GameFetcher.ts"; import { GameFetcher } from "./GameFetcher.ts";
import { DEFAULT_ENV, Env } from "./env.ts"; import { DEFAULT_ENV, Env } from "./env.ts";
import { SPLATOON3_TITLE_ID } from "./constant.ts"; import { SPLATOON3_TITLE_ID } from "./constant.ts";
import { USERAGENT } from "./constant.ts";
export type Opts = { export type Opts = {
profilePath: string; profilePath: string;
@ -400,11 +401,17 @@ export class App {
} }
async monitorWithNxapi() { async monitorWithNxapi() {
this.env.logger.debug("Monitoring with nxapi presence"); this.env.logger.debug("Monitoring with nxapi presence");
const fetcher = this.env.newFetcher();
await this.exportOnce(); await this.exportOnce();
while (true) { while (true) {
await this.countDown(this.profile.state.monitorInterval); await this.countDown(this.profile.state.monitorInterval);
const nxapiResponse = await fetch(this.opts.nxapiPresenceUrl!); const nxapiResponse = await fetcher.get({
url: this.opts.nxapiPresenceUrl!,
headers: {
"User-Agent": USERAGENT,
},
});
const nxapiData = await nxapiResponse.json(); const nxapiData = await nxapiResponse.json();
const isSplatoon3Active = nxapiData.title?.id === SPLATOON3_TITLE_ID; const isSplatoon3Active = nxapiData.title?.id === SPLATOON3_TITLE_ID;
if (isSplatoon3Active || this.splatoon3PreviouslyActive) { if (isSplatoon3Active || this.splatoon3PreviouslyActive) {