From 93c3c1c89c27b12aaa485fd7ebfc1d0a76c9fb89 Mon Sep 17 00:00:00 2001 From: Matt Isenhower Date: Sat, 11 Nov 2023 17:09:54 -0500 Subject: [PATCH 1/2] Move region determination to the data store --- src/components/SplatfestBox.vue | 13 +------------ src/stores/splatfests.mjs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/components/SplatfestBox.vue b/src/components/SplatfestBox.vue index 26989f7..7603200 100644 --- a/src/components/SplatfestBox.vue +++ b/src/components/SplatfestBox.vue @@ -3,7 +3,7 @@
{{ $t(title) }} - {{ regions.length < 4 ? ` (${regions.join('/')})` : '' }} + {{ festival.regions.length < 4 ? ` (${festival.regions.join('/')})` : '' }}
@@ -48,17 +48,6 @@ const props = defineProps({ historyMode: Boolean, }); -const regions = computed(() => { - const availableRegions = []; - const regions = props.festival.__splatoon3ink_id.split("-")[0]; - if (regions.includes("J")) availableRegions.push("JP"); - if (regions.includes("U")) availableRegions.push("NA"); - if (regions.includes("E")) availableRegions.push("EU"); - if (regions.includes("A")) availableRegions.push("AP"); - return availableRegions -}) - - const title = computed(() => { if (props.historyMode) { return 'festival.active'; diff --git a/src/stores/splatfests.mjs b/src/stores/splatfests.mjs index 4fc84f1..1e23eb0 100644 --- a/src/stores/splatfests.mjs +++ b/src/stores/splatfests.mjs @@ -23,11 +23,23 @@ function defineSplatfestRegionStore(region) { } } + function getRegions(node) { + let result = []; + const regions = node.__splatoon3ink_id.split("-")[0]; + if (regions.includes("J")) result.push("JP"); + if (regions.includes("U")) result.push("NA"); + if (regions.includes("E")) result.push("EU"); + if (regions.includes("A")) result.push("AP"); + + return result; + } + const festivals = computed(() => store.data?.[region]?.data.festRecords.nodes.map(node => { return { ...node, status: getStatus(node), hasResults: node.teams.some(t => t.result), + regions: getRegions(node), }; })); @@ -62,6 +74,7 @@ function defineSplatfestRegionStore(region) { isTricolorActive: time.isActive(fest.midtermTime, fest.endTime), startTime: fest.midtermTime, endTime: fest.endTime, + regions, }; }); From 7b013bf8b8968f41f80500fbdae170a24bf09f30 Mon Sep 17 00:00:00 2001 From: Matt Isenhower Date: Sat, 11 Nov 2023 17:15:27 -0500 Subject: [PATCH 2/2] Fix the Splatfest social status generators --- .../generators/SplatfestResultsStatus.mjs | 28 +++++------ app/social/generators/SplatfestStatus.mjs | 47 ++++++------------- 2 files changed, 25 insertions(+), 50 deletions(-) diff --git a/app/social/generators/SplatfestResultsStatus.mjs b/app/social/generators/SplatfestResultsStatus.mjs index b46ec2f..1f4a4f7 100644 --- a/app/social/generators/SplatfestResultsStatus.mjs +++ b/app/social/generators/SplatfestResultsStatus.mjs @@ -1,21 +1,17 @@ import StatusGenerator from "./StatusGenerator.mjs"; import Media from "../Media.mjs"; import { useUSSplatfestsStore, useEUSplatfestsStore, useJPSplatfestsStore, useAPSplatfestsStore } from '../../../src/stores/splatfests.mjs'; -import ValueCache from '../../common/ValueCache.mjs'; export default class SplatfestResultsStatus extends StatusGenerator { key = 'splatfestResults'; name = 'Splatfest Results'; - SplatfestStatus(region) { + constructor(region) { + super(); this.region = region; - } - - lastPostCache(client) { - // let US be no suffix for backwards compatibility - const regionSuffix = this.region === 'NA' ? '' : `.${this.region}`; - return new ValueCache(`social.${client.key}.${this.key}${regionSuffix}`); + this.key += `.${region}`; + this.name += ` (${region})`; } async getFestival() { @@ -51,22 +47,20 @@ export default class SplatfestResultsStatus extends StatusGenerator let winningTeam = festival.teams.find(t => t.result.isWinner); - return `Splatfest results: Team ${winningTeam.teamName} wins! #splatfest #splatoon3`; + const global = festival.regions.length == 4; + const regionText = global ? 'Global' : festival.regions.join("/"); + + return `${regionText} Splatfest results: Team ${winningTeam.teamName} wins! #splatfest #splatoon3`; } async shouldPost(client) { let festival = await this.getFestival(); - let regions = festival.__splatoon3ink_id.split("-")[0]; - switch(this.region) { - // PRIORITY - US, EU, JP, AP - case "NA": break; - case "EU": if(regions.includes("U")) return false; break; - case "JP": if(regions.includes("U") || regions.includes("E")) return false; break; - case "AP": if(regions.includes("U") || regions.includes("E") || regions.includes("J")) return false; break; + + if (festival?.regions[0] !== this.region) { + return false; } return super.shouldPost(client); - } async _getContentWrapper() { diff --git a/app/social/generators/SplatfestStatus.mjs b/app/social/generators/SplatfestStatus.mjs index b284ea4..ed72591 100644 --- a/app/social/generators/SplatfestStatus.mjs +++ b/app/social/generators/SplatfestStatus.mjs @@ -2,24 +2,19 @@ import StatusGenerator from "./StatusGenerator.mjs"; import Media from "../Media.mjs"; import { useUSSplatfestsStore, useEUSplatfestsStore, useJPSplatfestsStore, useAPSplatfestsStore, STATUS_ACTIVE, STATUS_PAST } from '../../../src/stores/splatfests.mjs'; import { useTimeStore } from "../../../src/stores/time.mjs"; -import ValueCache from '../../common/ValueCache.mjs'; export default class SplatfestStatus extends StatusGenerator { key = 'splatfest'; name = 'Splatfest'; - SplatfestStatus(region) { + constructor(region) { + super(); this.region = region; + this.key += `.${region}`; + this.name += ` (${region})`; } - lastPostCache(client) { - // let US be no suffix for backwards compatibility - const regionSuffix = this.region === 'NA' ? '' : `.${this.region}`; - return new ValueCache(`social.${client.key}.${this.key}${regionSuffix}`); - } - - async getFestival() { await this.preparePinia(); let store; @@ -69,19 +64,12 @@ export default class SplatfestStatus extends StatusGenerator } async shouldPost(client) { - let festival = await this.getFestival(); - let regions = festival.__splatoon3ink_id.split("-")[0]; - switch(this.region) { - // PRIORITY - US, EU, JP, AP - case "NA": break; - case "EU": if(regions.includes("U")) return false; break; - case "JP": if(regions.includes("U") || regions.includes("E")) return false; break; - case "AP": if(regions.includes("U") || regions.includes("E") || regions.includes("J")) return false; break; + + if (festival?.regions[0] !== this.region) { + return false; } - - let currentId = await this.getDataTime(); let cachedId = await this.lastPostCache(client).getData(); @@ -97,27 +85,20 @@ export default class SplatfestStatus extends StatusGenerator return false; } - const availableRegions = []; - const regions = festival.__splatoon3ink_id.split("-")[0]; - if (regions.includes("J")) availableRegions.push("JP"); - if (regions.includes("U")) availableRegions.push("NA"); - if (regions.includes("E")) availableRegions.push("EU"); - if (regions.includes("A")) availableRegions.push("AP"); - - const global = availableRegions.length == 4; - const regionText = !global ? ` (${availableRegions.join("/")})` : ''; + const global = festival.regions.length == 4; + const regionText = global ? 'global' : festival.regions.join("/"); switch (state) { case 'upcoming': - return `You can now vote in the next ${global ? 'global ' : ''}Splatfest: ${festival.title}${regionText} #splatfest #splatoon3`; + return `You can now vote in the next ${regionText} Splatfest: ${festival.title} #splatfest #splatoon3`; case 'upcoming:3d': - return `Reminder: The next ${global ? 'global ' : ''}Splatfest starts in 3 DAYS! ${festival.title}${regionText} #splatfest #splatoon3` + return `Reminder: The next ${regionText} Splatfest starts in 3 DAYS! ${festival.title} #splatfest #splatoon3` case 'upcoming:1d': - return `Reminder: The next ${global ? 'global ' : ''}Splatfest starts in 24 HOURS! ${festival.title}${regionText} #splatfest #splatoon3` + return `Reminder: The next ${regionText} Splatfest starts in 24 HOURS! ${festival.title} #splatfest #splatoon3` case 'active': - return `The ${global ? 'global ' : ''}Splatfest is NOW OPEN! ${festival.title}${regionText} #splatfest #splatoon3` + return `The ${regionText} Splatfest is NOW OPEN! ${festival.title} #splatfest #splatoon3` case 'ended': - return `The ${global ? 'global ' : ''}Splatfest is now closed${regionText}. Results are usually posted within 2 hours! #splatfest #splatoon3` + return `The ${regionText} Splatfest is now closed. Results are usually posted within 2 hours! #splatfest #splatoon3` } }