Update SplatNet 3 types

This commit is contained in:
Samuel Elliott
2022-09-26 16:40:09 +01:00
parent b71246719a
commit d9fb2657e6
4 changed files with 132 additions and 51 deletions

View File

@@ -162,7 +162,7 @@ export class SplatNet3User {
const schedules = await this.getSchedules();
this.fest_vote_status =
!schedules.currentFest || new Date(schedules.currentFest.endTime).getTime() <= Date.now() ? null :
this.fest_vote_status?.data.fest.id === schedules.currentFest.id ?
this.fest_vote_status?.data.fest?.id === schedules.currentFest.id ?
await this.splatnet.getFestVotingStatusRefetch(schedules.currentFest.id) :
await this.splatnet.getFestVotingStatus(schedules.currentFest.id);
}, this.update_interval_fest_voting_status ?? this.update_interval);
@@ -208,7 +208,7 @@ function createApp(
const result: (Friend & {
splatoon3?: FriendListResult['friends']['nodes'][0] | null;
splatoon3_fest_team?: DetailVotingStatusResult['fest']['teams'][0] | null;
splatoon3_fest_team?: Exclude<DetailVotingStatusResult['fest'], null>['teams'][0] | null;
})[] = [];
const users = await Promise.all(user_ids.map(async id => {
@@ -305,7 +305,7 @@ function createApp(
let match_splatnet3_fest_team:
Exclude<StageScheduleResult['currentFest'], null>['teams'][0] | null | undefined = undefined;
let match_splatnet3_fest_team_vote_status:
DetailVotingStatusResult['fest']['teams'][0] | null | undefined = undefined;
Exclude<DetailVotingStatusResult['fest'], null>['teams'][0] | null | undefined = undefined;
const additional_response_data: {
splatoon3_vs_setting?:
@@ -482,9 +482,9 @@ function createFestScheduleTeam(
}
function createFestVoteTeam(
team: DetailVotingStatusResult['fest']['teams'][0],
team: Exclude<DetailVotingStatusResult['fest'], null>['teams'][0],
state?: FestVoteState | null
): DetailVotingStatusResult['fest']['teams'][0] {
): Exclude<DetailVotingStatusResult['fest'], null>['teams'][0] {
return {
id: team.id,
teamName: team.teamName,

View File

@@ -4,6 +4,7 @@ import type { Arguments as ParentArguments } from '../splatnet3.js';
import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js';
import { initStorage } from '../../util/storage.js';
import { getBulletToken } from '../../common/auth/splatnet3.js';
import { FestState } from '../../api/splatnet3-types.js';
const debug = createDebug('cli:splatnet3:festival');
@@ -53,40 +54,42 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
}
const detail = await splatnet.getFestDetail(fest.id);
const votes = await splatnet.getFestVotingStatus(fest.id);
const votes = detail.data.fest.state !== FestState.CLOSED ? await splatnet.getFestVotingStatus(fest.id) : null;
if (argv.jsonPrettyPrint) {
console.log(JSON.stringify({fest: detail.data.fest, votes: votes.data.fest}, null, 4));
console.log(JSON.stringify({fest: detail.data.fest, votes: votes?.data.fest ?? undefined}, null, 4));
return;
}
if (argv.json) {
console.log(JSON.stringify({fest: detail.data.fest, votes: votes.data.fest}));
console.log(JSON.stringify({fest: detail.data.fest, votes: votes?.data.fest ?? undefined}));
return;
}
console.log('Details', detail.data.fest);
const table = new Table({
head: [
'Name',
'State',
'Team',
],
});
if (votes) {
const table = new Table({
head: [
'Name',
'State',
'Team',
],
});
for (const team of votes.data.fest.teams) {
for (const vote of team.votes.nodes) {
table.push([vote.playerName, 'Voted', team.teamName]);
for (const team of votes.data.fest.teams) {
for (const vote of team.votes?.nodes ?? []) {
table.push([vote.playerName, 'Voted', team.teamName]);
}
for (const vote of team.preVotes?.nodes ?? []) {
table.push([vote.playerName, 'Planning to vote', team.teamName]);
}
}
for (const vote of team.preVotes.nodes) {
table.push([vote.playerName, 'Planning to vote', team.teamName]);
for (const vote of votes.data.fest.undecidedVotes?.nodes ?? []) {
table.push([vote.playerName, 'Undecided', '-']);
}
}
for (const vote of votes.data.fest.undecidedVotes.nodes) {
table.push([vote.playerName, 'Undecided', '-']);
console.log('Friends votes');
console.log(table.toString());
}
console.log('Friends votes');
console.log(table.toString());
}