mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-10-13 04:49:33 -05:00
Update SplatNet 3 revision and add support for Big Run for Splatoon 3 presence
This commit is contained in:
@@ -2,7 +2,7 @@ import * as net from 'node:net';
|
||||
import createDebug from 'debug';
|
||||
import express, { Request, Response } from 'express';
|
||||
import * as persist from 'node-persist';
|
||||
import { BankaraMatchMode, BankaraMatchSetting, CoopSetting, DetailVotingStatusResult, FestMatchSetting, FestState, FestTeam_schedule, FestTeam_votingStatus, FestVoteState, Fest_schedule, Friend as SplatNetFriend, FriendListResult, FriendOnlineState, GraphQLSuccessResponse, LeagueMatchSetting, RegularMatchSetting, StageScheduleResult, VsMode, XMatchSetting } from 'splatnet3-types/splatnet3';
|
||||
import { BankaraMatchMode, BankaraMatchSetting, CoopSetting, DetailVotingStatusResult, FestMatchSetting, FestState, FestTeam_schedule, FestTeam_votingStatus, FestVoteState, Fest_schedule, FriendListResult, FriendOnlineState, Friend_friendList, GraphQLSuccessResponse, LeagueMatchSetting, RegularMatchSetting, StageScheduleResult, VsMode, XMatchSetting } from 'splatnet3-types/splatnet3';
|
||||
import type { Arguments as ParentArguments } from '../cli.js';
|
||||
import { ArgumentsCamelCase, Argv, YargsArguments } from '../util/yargs.js';
|
||||
import { initStorage } from '../util/storage.js';
|
||||
@@ -22,12 +22,12 @@ const debug = createDebug('cli:presence-server');
|
||||
type CoopSetting_schedule = Pick<CoopSetting, '__typename' | 'coopStage' | 'weapons'>;
|
||||
|
||||
interface AllUsersResult extends Friend {
|
||||
splatoon3?: SplatNetFriend | null;
|
||||
splatoon3?: Friend_friendList | null;
|
||||
splatoon3_fest_team?: FestTeam_votingStatus | null;
|
||||
}
|
||||
interface PresenceResponse {
|
||||
friend: Friend;
|
||||
splatoon3?: SplatNetFriend | null;
|
||||
splatoon3?: Friend_friendList | null;
|
||||
splatoon3_fest_team?: (FestTeam_schedule & FestTeam_votingStatus) | null;
|
||||
splatoon3_vs_setting?:
|
||||
RegularMatchSetting | BankaraMatchSetting | FestMatchSetting |
|
||||
@@ -157,7 +157,7 @@ export class SplatNet3User {
|
||||
}
|
||||
}
|
||||
|
||||
async getFriends(): Promise<SplatNetFriend[]> {
|
||||
async getFriends(): Promise<Friend_friendList[]> {
|
||||
await this.update('friends', async () => {
|
||||
this.friends = await this.splatnet.getFriendsRefetch();
|
||||
}, this.update_interval);
|
||||
@@ -465,7 +465,10 @@ class Server extends HttpServer {
|
||||
friend.onlineState === FriendOnlineState.COOP_MODE_FIGHTING
|
||||
) {
|
||||
const schedules = await user.getSchedules();
|
||||
const coop_setting = getSchedule(schedules.coopGroupingSchedule.regularSchedules)?.setting;
|
||||
const coop_schedules = friend.coopMode === 'BIG_RUN' ?
|
||||
schedules.coopGroupingSchedule.bigRunSchedules :
|
||||
schedules.coopGroupingSchedule.regularSchedules;
|
||||
const coop_setting = getSchedule(coop_schedules)?.setting;
|
||||
|
||||
response.splatoon3_coop_setting = coop_setting ?? null;
|
||||
}
|
||||
@@ -608,7 +611,6 @@ function createFestScheduleTeam(
|
||||
id: team.id,
|
||||
color: team.color,
|
||||
myVoteState: state,
|
||||
role: team.role,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ export async function dumpFestRecords(splatnet: SplatNet3Api, directory: string,
|
||||
// Fetch this now to match the behavour of Nintendo's app
|
||||
if (!record) {
|
||||
const result = await splatnet.getFestDetail(fest_record.id);
|
||||
record = result.data.fest;
|
||||
record = result.data.fest!;
|
||||
}
|
||||
|
||||
const rankings_available = record.state === FestState.CLOSED &&
|
||||
|
||||
@@ -46,28 +46,29 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
const req_id = argv.id;
|
||||
const encoded_req_id = Buffer.from(req_id).toString('base64');
|
||||
const encoded_part_req_id = Buffer.from('Fest-' + req_id).toString('base64');
|
||||
const fest = fest_records.data.festRecords.nodes.find(f => f.id === req_id ||
|
||||
const fest_record = fest_records.data.festRecords.nodes.find(f => f.id === req_id ||
|
||||
f.id === encoded_req_id || f.id === encoded_part_req_id);
|
||||
|
||||
if (!fest) {
|
||||
if (!fest_record) {
|
||||
throw new Error('Invalid Splatfest ID');
|
||||
}
|
||||
|
||||
const detail = await splatnet.getFestDetail(fest.id);
|
||||
const votes = detail.data.fest.state !== FestState.CLOSED ? await splatnet.getFestVotingStatus(fest.id) : null;
|
||||
const fest = (await splatnet.getFestDetail(fest_record.id)).data.fest!;
|
||||
const fest_votes = fest.state !== FestState.CLOSED ?
|
||||
(await splatnet.getFestVotingStatus(fest_record.id)).data.fest : null;
|
||||
|
||||
if (argv.jsonPrettyPrint) {
|
||||
console.log(JSON.stringify({fest: detail.data.fest, votes: votes?.data.fest ?? undefined}, null, 4));
|
||||
console.log(JSON.stringify({fest: fest, votes: fest_votes ?? undefined}, null, 4));
|
||||
return;
|
||||
}
|
||||
if (argv.json) {
|
||||
console.log(JSON.stringify({fest: detail.data.fest, votes: votes?.data.fest ?? undefined}));
|
||||
console.log(JSON.stringify({fest: fest, votes: fest_votes ?? undefined}));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Details', detail.data.fest);
|
||||
console.log('Details', fest);
|
||||
|
||||
if (votes) {
|
||||
if (fest_votes) {
|
||||
const table = new Table({
|
||||
head: [
|
||||
'Name',
|
||||
@@ -76,7 +77,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
],
|
||||
});
|
||||
|
||||
for (const team of votes.data.fest.teams) {
|
||||
for (const team of fest_votes.teams) {
|
||||
for (const vote of team.votes?.nodes ?? []) {
|
||||
table.push([vote.playerName, 'Voted', team.teamName]);
|
||||
}
|
||||
@@ -85,7 +86,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
}
|
||||
}
|
||||
|
||||
for (const vote of votes.data.fest.undecidedVotes?.nodes ?? []) {
|
||||
for (const vote of fest_votes.undecidedVotes?.nodes ?? []) {
|
||||
table.push([vote.playerName, 'Undecided', '-']);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import createDebug from 'debug';
|
||||
import { FriendOnlineState } from 'splatnet3-types/splatnet3';
|
||||
import { FriendOnlineState, Friend_friendList } from 'splatnet3-types/splatnet3';
|
||||
import Table from '../util/table.js';
|
||||
import type { Arguments as ParentArguments } from '../splatnet3.js';
|
||||
import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js';
|
||||
@@ -53,7 +53,6 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
'NSA ID',
|
||||
'Name',
|
||||
'Status',
|
||||
'Favourite?',
|
||||
'Locked?',
|
||||
'Voice chat?',
|
||||
],
|
||||
@@ -69,8 +68,9 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
friend.playerName === friend.nickname ? friend.playerName :
|
||||
friend.playerName ? friend.playerName + ' (' + friend.nickname + ')' :
|
||||
friend.nickname,
|
||||
getStateDescription(friend.onlineState, getVsModeDescription(friend.vsMode) ?? friend.vsMode?.name),
|
||||
friend.isFavorite ? 'Yes' : 'No',
|
||||
getStateDescription(friend.onlineState,
|
||||
getVsModeDescription(friend.vsMode) ?? friend.vsMode?.name,
|
||||
getCoopModeDescription(friend.coopMode) ?? undefined),
|
||||
typeof friend.isLocked === 'boolean' ? friend.isLocked ? 'Yes' : 'No' : '-',
|
||||
typeof friend.isVcEnabled === 'boolean' ? friend.isVcEnabled ? 'Yes' : 'No' : '-',
|
||||
]);
|
||||
@@ -79,7 +79,7 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
||||
console.log(table.toString());
|
||||
}
|
||||
|
||||
function getStateDescription(state: FriendOnlineState, vs_mode_desc?: string) {
|
||||
function getStateDescription(state: FriendOnlineState, vs_mode_desc?: string, coop_mode_desc?: string) {
|
||||
switch (state) {
|
||||
case FriendOnlineState.OFFLINE:
|
||||
return 'Offline';
|
||||
@@ -88,16 +88,16 @@ function getStateDescription(state: FriendOnlineState, vs_mode_desc?: string) {
|
||||
case FriendOnlineState.VS_MODE_MATCHING:
|
||||
return 'In lobby (' + (vs_mode_desc ?? 'VS') + ')';
|
||||
case FriendOnlineState.COOP_MODE_MATCHING:
|
||||
return 'In lobby (Salmon Run)';
|
||||
return 'In lobby (' + (coop_mode_desc ?? 'Salmon Run') + ')';
|
||||
case FriendOnlineState.VS_MODE_FIGHTING:
|
||||
return 'In game (' + (vs_mode_desc ?? 'VS') + ')';
|
||||
case FriendOnlineState.COOP_MODE_FIGHTING:
|
||||
return 'In game (Salmon Run)';
|
||||
return 'In game (' + (coop_mode_desc ?? 'Salmon Run') + ')';
|
||||
default: return state;
|
||||
}
|
||||
}
|
||||
|
||||
function getVsModeDescription(vs_mode: {id: string; mode: string;} | null) {
|
||||
function getVsModeDescription(vs_mode: Friend_friendList['vsMode'] | null) {
|
||||
if (!vs_mode) return null;
|
||||
|
||||
if (vs_mode.mode === 'REGULAR') return 'Regular Battle';
|
||||
@@ -113,3 +113,12 @@ function getVsModeDescription(vs_mode: {id: string; mode: string;} | null) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getCoopModeDescription(coop_mode: string | null) {
|
||||
if (!coop_mode) return null;
|
||||
|
||||
if (coop_mode === 'REGULAR') return 'Salmon Run';
|
||||
if (coop_mode === 'BIG_RUN') return 'Big Run';
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ async function update(
|
||||
|
||||
const pager = await splatnet.getBattleHistoryDetailPagerRefetch(latest_id);
|
||||
|
||||
if (pager.data.vsHistoryDetail.nextHistoryDetail) {
|
||||
if (pager.data.vsHistoryDetail?.nextHistoryDetail) {
|
||||
// New battle results available
|
||||
debug('New battle result', pager.data.vsHistoryDetail.nextHistoryDetail);
|
||||
vs = await dumpResults(splatnet, directory, vs.battles.data);
|
||||
@@ -204,7 +204,7 @@ async function update(
|
||||
|
||||
const pager = await splatnet.getCoopHistoryDetailRefetch(latest_id);
|
||||
|
||||
if (pager.data.node.nextHistoryDetail) {
|
||||
if (pager.data.node?.nextHistoryDetail) {
|
||||
// New coop results available
|
||||
debug('New coop result', pager.data.node.nextHistoryDetail);
|
||||
coop = await dumpCoopResults(splatnet, directory, coop.results.data);
|
||||
|
||||
Reference in New Issue
Block a user