feat: add summary export to App
parent
aabc9cf733
commit
2d937478ab
|
|
@ -24,6 +24,7 @@ Options:
|
||||||
--monitor, -m Monitor mode
|
--monitor, -m Monitor mode
|
||||||
--skip-mode <mode>, -s Skip mode (default: null)
|
--skip-mode <mode>, -s Skip mode (default: null)
|
||||||
("vs", "coop")
|
("vs", "coop")
|
||||||
|
--with-summary Include summary in the output
|
||||||
--help Show this help message and exit`,
|
--help Show this help message and exit`,
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
4
s3si.ts
4
s3si.ts
|
|
@ -5,7 +5,7 @@ import { flags } from "./deps.ts";
|
||||||
const parseArgs = (args: string[]) => {
|
const parseArgs = (args: string[]) => {
|
||||||
const parsed = flags.parse(args, {
|
const parsed = flags.parse(args, {
|
||||||
string: ["profilePath", "exporter", "skipMode"],
|
string: ["profilePath", "exporter", "skipMode"],
|
||||||
boolean: ["help", "noProgress", "monitor"],
|
boolean: ["help", "noProgress", "monitor", "withSummary"],
|
||||||
alias: {
|
alias: {
|
||||||
"help": "h",
|
"help": "h",
|
||||||
"profilePath": ["p", "profile-path"],
|
"profilePath": ["p", "profile-path"],
|
||||||
|
|
@ -13,6 +13,7 @@ const parseArgs = (args: string[]) => {
|
||||||
"noProgress": ["n", "no-progress"],
|
"noProgress": ["n", "no-progress"],
|
||||||
"monitor": ["m"],
|
"monitor": ["m"],
|
||||||
"skipMode": ["s", "skip-mode"],
|
"skipMode": ["s", "skip-mode"],
|
||||||
|
"withSummary": "with-summary",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return parsed;
|
return parsed;
|
||||||
|
|
@ -32,6 +33,7 @@ Options:
|
||||||
--monitor, -m Monitor mode
|
--monitor, -m Monitor mode
|
||||||
--skip-mode <mode>, -s Skip mode (default: null)
|
--skip-mode <mode>, -s Skip mode (default: null)
|
||||||
("vs", "coop")
|
("vs", "coop")
|
||||||
|
--with-summary Include summary in the output
|
||||||
--help Show this help message and exit`,
|
--help Show this help message and exit`,
|
||||||
);
|
);
|
||||||
Deno.exit(0);
|
Deno.exit(0);
|
||||||
|
|
|
||||||
39
src/app.ts
39
src/app.ts
|
|
@ -15,6 +15,7 @@ export type Opts = {
|
||||||
exporter: string;
|
exporter: string;
|
||||||
noProgress: boolean;
|
noProgress: boolean;
|
||||||
monitor: boolean;
|
monitor: boolean;
|
||||||
|
withSummary: boolean;
|
||||||
skipMode?: string;
|
skipMode?: string;
|
||||||
cache?: Cache;
|
cache?: Cache;
|
||||||
stateBackend?: StateBackend;
|
stateBackend?: StateBackend;
|
||||||
|
|
@ -26,6 +27,7 @@ export const DEFAULT_OPTS: Opts = {
|
||||||
exporter: "stat.ink",
|
exporter: "stat.ink",
|
||||||
noProgress: false,
|
noProgress: false,
|
||||||
monitor: false,
|
monitor: false,
|
||||||
|
withSummary: false,
|
||||||
env: DEFAULT_ENV,
|
env: DEFAULT_ENV,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -157,7 +159,7 @@ export class App {
|
||||||
const skipMode = this.getSkipMode();
|
const skipMode = this.getSkipMode();
|
||||||
const errors: unknown[] = [];
|
const errors: unknown[] = [];
|
||||||
|
|
||||||
if (skipMode.includes("vs")) {
|
if (skipMode.includes("vs") || exporters.length === 0) {
|
||||||
this.env.logger.log("Skip exporting VS games.");
|
this.env.logger.log("Skip exporting VS games.");
|
||||||
} else {
|
} else {
|
||||||
this.env.logger.log("Fetching battle list...");
|
this.env.logger.log("Fetching battle list...");
|
||||||
|
|
@ -211,7 +213,7 @@ export class App {
|
||||||
|
|
||||||
stats = initStats();
|
stats = initStats();
|
||||||
|
|
||||||
if (skipMode.includes("coop")) {
|
if (skipMode.includes("coop") || exporters.length === 0) {
|
||||||
this.env.logger.log("Skip exporting coop games.");
|
this.env.logger.log("Skip exporting coop games.");
|
||||||
} else {
|
} else {
|
||||||
this.env.logger.log("Fetching coop battle list...");
|
this.env.logger.log("Fetching coop battle list...");
|
||||||
|
|
@ -255,6 +257,39 @@ export class App {
|
||||||
throw errors[0];
|
throw errors[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const summaryExporters = exporters.filter((e) => e.exportSummary);
|
||||||
|
if (!this.opts.withSummary || summaryExporters.length === 0) {
|
||||||
|
this.env.logger.log("Skip exporting summary.");
|
||||||
|
} else {
|
||||||
|
this.env.logger.log("Fetching summary...");
|
||||||
|
const summary = await splatnet.getSummary();
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
summaryExporters.map((e) =>
|
||||||
|
showError(
|
||||||
|
this.env,
|
||||||
|
e.exportSummary!(summary),
|
||||||
|
).then((result) => {
|
||||||
|
if (result.status === "success") {
|
||||||
|
this.env.logger.log(`Exported summary to ${result.url}`);
|
||||||
|
} else if (result.status === "skip") {
|
||||||
|
this.env.logger.log(`Skipped exporting summary to ${e.name}`);
|
||||||
|
} else {
|
||||||
|
const _never: never = result;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
errors.push(err);
|
||||||
|
this.env.logger.error(`\nFailed to export to ${e.name}:`, err);
|
||||||
|
})
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (errors.length > 0) {
|
||||||
|
throw errors[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async monitor() {
|
async monitor() {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import {
|
||||||
GraphQLResponse,
|
GraphQLResponse,
|
||||||
Queries,
|
Queries,
|
||||||
RespMap,
|
RespMap,
|
||||||
|
Summary,
|
||||||
VarsMap,
|
VarsMap,
|
||||||
} from "./types.ts";
|
} from "./types.ts";
|
||||||
import { DEFAULT_ENV, Env } from "./env.ts";
|
import { DEFAULT_ENV, Env } from "./env.ts";
|
||||||
|
|
@ -223,6 +224,19 @@ export class Splatnet3 {
|
||||||
|
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getSummary(): Promise<Summary> {
|
||||||
|
const ConfigureAnalyticsQuery = await this.request(
|
||||||
|
Queries.ConfigureAnalyticsQuery,
|
||||||
|
);
|
||||||
|
const HistoryRecordQuery = await this.request(Queries.HistoryRecordQuery);
|
||||||
|
const CoopHistoryQuery = await this.request(Queries.CoopHistoryQuery);
|
||||||
|
return {
|
||||||
|
ConfigureAnalyticsQuery,
|
||||||
|
HistoryRecordQuery,
|
||||||
|
CoopHistoryQuery,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIdsFromGroups<T extends { id: string }>(
|
function getIdsFromGroups<T extends { id: string }>(
|
||||||
|
|
|
||||||
|
|
@ -310,13 +310,19 @@ export type SummaryFetcher = {
|
||||||
): Promise<RespMap[T]>;
|
): Promise<RespMap[T]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Summary = {
|
||||||
|
ConfigureAnalyticsQuery: RespMap[Queries.ConfigureAnalyticsQuery];
|
||||||
|
HistoryRecordQuery: RespMap[Queries.HistoryRecordQuery];
|
||||||
|
CoopHistoryQuery: RespMap[Queries.CoopHistoryQuery];
|
||||||
|
};
|
||||||
|
|
||||||
export type GameExporter = {
|
export type GameExporter = {
|
||||||
name: string;
|
name: string;
|
||||||
notExported: (
|
notExported: (
|
||||||
{ type, list }: { type: Game["type"]; list: string[] },
|
{ type, list }: { type: Game["type"]; list: string[] },
|
||||||
) => Promise<string[]>;
|
) => Promise<string[]>;
|
||||||
exportGame: (game: Game) => Promise<ExportResult>;
|
exportGame: (game: Game) => Promise<ExportResult>;
|
||||||
exportSummary?: (fetcher: SummaryFetcher) => Promise<ExportResult>;
|
exportSummary?: (summary: Summary) => Promise<ExportResult>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BankaraBattleHistories = {
|
export type BankaraBattleHistories = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue