diff --git a/s3si.ts b/s3si.ts index cae0203..8f7affa 100644 --- a/s3si.ts +++ b/s3si.ts @@ -32,8 +32,7 @@ Options: (e.g. "stat.ink,file") --list-method When set to "latest", the latest 50 matches will be obtained. When set to "all", matches of all modes will be obtained with a maximum of 250 matches (5 modes x 50 matches). - When set to "auto", the latest 50 matches will be obtained. If 50 matches have not been uploaded yet, matches will be obtained from the list of all modes. - "auto" is the default setting. + "latest" is the default setting. --no-progress, -n Disable progress bar --monitor, -m Monitor mode --skip-mode , -s Skip mode (default: null) diff --git a/src/RankTracker.ts b/src/RankTracker.ts index ba95181..145d7a0 100644 --- a/src/RankTracker.ts +++ b/src/RankTracker.ts @@ -5,7 +5,7 @@ import { HistoryGroups, RankParam, } from "./types.ts"; -import { gameId, parseHistoryDetailId } from "./utils.ts"; +import { battleTime, gameId } from "./utils.ts"; import { getSeason } from "./VersionData.ts"; const splusParams = () => { @@ -193,17 +193,6 @@ function addRank( }; } -const battleTime = (id: string) => { - const { timestamp } = parseHistoryDetailId(id); - - const dateStr = timestamp.replace( - /(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})/, - "$1-$2-$3T$4:$5:$6Z", - ); - - return new Date(dateStr); -}; - type FlattenItem = { id: string; gameId: string; diff --git a/src/app.ts b/src/app.ts index dbd6e6c..ba246d2 100644 --- a/src/app.ts +++ b/src/app.ts @@ -10,8 +10,6 @@ import { delay, showError } from "./utils.ts"; import { GameFetcher } from "./GameFetcher.ts"; import { DEFAULT_ENV, Env } from "./env.ts"; -export type ListMethod = "latest" | "all" | "auto"; - export type Opts = { profilePath: string; exporter: string; @@ -31,7 +29,7 @@ export const DEFAULT_OPTS: Opts = { noProgress: false, monitor: false, withSummary: false, - listMethod: "auto", + listMethod: "latest", env: DEFAULT_ENV, }; @@ -167,7 +165,12 @@ export class App { this.env.logger.log("Skip exporting VS games."); } else { this.env.logger.log("Fetching battle list..."); - const gameList = await splatnet.getBattleList(); + let gameList: string[]; + if (this.opts.listMethod === "all") { + gameList = await splatnet.getAllBattleList(); + } else { + gameList = await splatnet.getBattleList(); + } const { redraw, endBar } = this.exporterProgress("Export vs games"); const fetcher = new GameFetcher({ diff --git a/src/splatnet3.ts b/src/splatnet3.ts index 080c8fa..b3d76c5 100644 --- a/src/splatnet3.ts +++ b/src/splatnet3.ts @@ -15,7 +15,7 @@ import { } from "./types.ts"; import { DEFAULT_ENV, Env } from "./env.ts"; import { getBulletToken, getGToken } from "./iksm.ts"; -import { parseHistoryDetailId } from "./utils.ts"; +import { battleTime, parseHistoryDetailId } from "./utils.ts"; export class Splatnet3 { protected profile: Profile; @@ -137,6 +137,12 @@ export class Splatnet3 { [BattleListType.Bankara]: () => this.request(Queries.BankaraBattleHistoriesQuery) .then((r) => getIdsFromGroups(r.bankaraBattleHistories)), + [BattleListType.XBattle]: () => + this.request(Queries.XBattleHistoriesQuery) + .then((r) => getIdsFromGroups(r.xBattleHistories)), + [BattleListType.Event]: () => + this.request(Queries.EventBattleHistoriesQuery) + .then((r) => getIdsFromGroups(r.eventBattleHistories)), [BattleListType.Private]: () => this.request(Queries.PrivateBattleHistoriesQuery) .then((r) => getIdsFromGroups(r.privateBattleHistories)), @@ -168,6 +174,30 @@ export class Splatnet3 { return await this.BATTLE_LIST_TYPE_MAP[battleListType](); } + // Get all id from all battle list, sort by time, [0] is the latest + async getAllBattleList() { + const ALL_TYPE: BattleListType[] = [ + BattleListType.Regular, + BattleListType.Bankara, + BattleListType.XBattle, + BattleListType.Event, + BattleListType.Private, + ]; + const ids: string[] = []; + for (const type of ALL_TYPE) { + ids.push(...await this.getBattleList(type)); + } + + // battleTime() + const timeMap = new Map( + ids.map((id) => [id, battleTime(id)] as const), + ); + + return ids.sort((a, b) => + timeMap.get(b)!.getTime() - timeMap.get(a)!.getTime() + ); + } + getBattleDetail( id: string, ) { diff --git a/src/types.ts b/src/types.ts index 1643ca8..705de00 100644 --- a/src/types.ts +++ b/src/types.ts @@ -607,10 +607,14 @@ export enum BattleListType { Latest, Regular, Bankara, + Event, + XBattle, Private, Coop, } +export type ListMethod = "latest" | "all"; + export type StatInkUuidList = { status: number; code: number; diff --git a/src/utils.ts b/src/utils.ts index 53dd34e..0bd356a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -188,3 +188,14 @@ export function urlSimplify(url: string): { pathname: string } | string { return url; } } + +export const battleTime = (id: string) => { + const { timestamp } = parseHistoryDetailId(id); + + const dateStr = timestamp.replace( + /(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})/, + "$1-$2-$3T$4:$5:$6Z", + ); + + return new Date(dateStr); +};