From cdf175a3bd817b58295860c74014786c7a726e41 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 2 Apr 2025 18:38:14 +0100 Subject: [PATCH] Fix presence server Splatoon 3 data --- rollup.config.js | 1 + src/cli/presence-server.ts | 19 +++++++++++++++---- src/common/presence-embed.ts | 2 +- src/discord/monitor/splatoon3.ts | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index f5158ea..1c1788a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -110,6 +110,7 @@ const main = { 'node-notifier', 'register-scheme', 'bindings', + 'node:string_decoder/', ], watch, }; diff --git a/src/cli/presence-server.ts b/src/cli/presence-server.ts index 96e166d..68b1113 100644 --- a/src/cli/presence-server.ts +++ b/src/cli/presence-server.ts @@ -7,7 +7,8 @@ import express, { Request, Response } from 'express'; import { fetch } from 'undici'; import * as persist from 'node-persist'; import mimetypes from 'mime-types'; -import { BankaraMatchSetting_schedule, CoopRule, CoopSetting_schedule, DetailFestRecordDetailResult, DetailVotingStatusResult, FestMatchSetting_schedule, FestRecordResult, FestState, FestTeam_schedule, FestTeam_votingStatus, FestVoteState, Fest_schedule, FriendListResult, FriendOnlineState, Friend_friendList, GraphQLSuccessResponse, KnownRequestId, LeagueMatchSetting_schedule, RegularMatchSetting_schedule, StageScheduleResult, XMatchSetting_schedule } from 'splatnet3-types/splatnet3'; +import { BankaraMatchSetting_schedule, CoopRule, CoopSetting_schedule, DetailFestRecordDetailResult, DetailVotingStatusResult, FestMatchSetting_schedule, FestState, FestTeam_schedule, FestTeam_votingStatus, FestVoteState, Fest_schedule, FriendListResult, FriendOnlineState, Friend_friendList, GraphQLSuccessResponse, KnownRequestId, LeagueMatchSetting_schedule, RegularMatchSetting_schedule, StageScheduleResult, XMatchSetting_schedule } from 'splatnet3-types/splatnet3'; +import FestRecordQuery_c8660a6 from 'splatnet3-types/graphql/c8660a636e73dcbf55c12932bc301b1c9db2aa9a78939ff61bf77a0ea8ff0a88'; import type { Arguments as ParentArguments } from '../cli.js'; import { git, product, version } from '../util/product.js'; import Users, { CoralUser } from '../common/users.js'; @@ -37,6 +38,16 @@ enum PresenceScope { SPLATOON3_FEST_TEAM = 'splatoon3_fest_team', } +interface FestRecordResult_c8660a63 { + currentPlayer: FestRecordQuery_c8660a6['currentPlayer']; + festRecords: { + edges: { + node: FestRecordQuery_c8660a6['festRecords']['nodes'][0]; + }[]; + }; +} +type FestRecordResult = FestRecordResult_c8660a63; + interface AllUsersResult extends Friend { title: TitleResult | null; splatoon3?: Friend_friendList | null; @@ -387,11 +398,11 @@ class SplatNet3ApiUser extends SplatNet3User { } await this.update('fest_records', async () => { - this.fest_records = await this.splatnet.getFestRecords(); + this.fest_records = await this.splatnet.persistedQuery('c8660a636e73dcbf55c12932bc301b1c9db2aa9a78939ff61bf77a0ea8ff0a88', {}); }, this.update_interval_schedules); - const current_or_upcoming_fest = this.fest_records!.data.festRecords.nodes.find(fest => - new Date(fest.endTime).getTime() >= Date.now()); + const current_or_upcoming_fest = this.fest_records!.data.festRecords.edges.find(edge => + new Date(edge.node.endTime).getTime() >= Date.now())?.node; if (!current_or_upcoming_fest) return null; const fest_detail = await this.getFestDetailData(current_or_upcoming_fest.id); diff --git a/src/common/presence-embed.ts b/src/common/presence-embed.ts index 745c577..b736938 100644 --- a/src/common/presence-embed.ts +++ b/src/common/presence-embed.ts @@ -279,7 +279,7 @@ function renderUserSplatoon3EmbedPartialSvg( ' - ' + setting.vsRule.name : '') + (result.splatoon3.onlineState === FriendOnlineState.VS_MODE_MATCHING ? ' (matching)' : ''); - if (result.splatoon3.vsMode.id === 'VnNNb2RlLTg=' && result.splatoon3_fest) { + if (result.splatoon3.vsMode.id === 'VnNNb2RlLTg=' && result.splatoon3_fest?.tricolorStage) { const stage = result.splatoon3_fest.tricolorStage; return [htmlentities` diff --git a/src/discord/monitor/splatoon3.ts b/src/discord/monitor/splatoon3.ts index 2cb4fb0..26062b6 100644 --- a/src/discord/monitor/splatoon3.ts +++ b/src/discord/monitor/splatoon3.ts @@ -342,7 +342,7 @@ export function callback(activity: DiscordRPC.Presence, game: Game, context?: Di ' - ' + setting.vsRule.name : '') + (friend.onlineState === FriendOnlineState.VS_MODE_MATCHING ? ' (matching)' : ''); - if (friend.vsMode.id === 'VnNNb2RlLTg=' && fest) { + if (friend.vsMode.id === 'VnNNb2RlLTg=' && fest?.tricolorStage) { const tricolour_stage_image = new URL(fest.tricolorStage.image.url); const match = tricolour_stage_image.pathname.match(/^\/resources\/prod\/(.+)$/); const proxy_stage_image =