Fix the Splatfest social status generators

This commit is contained in:
Matt Isenhower 2023-11-11 17:15:27 -05:00
parent 93c3c1c89c
commit 7b013bf8b8
2 changed files with 25 additions and 50 deletions

View File

@ -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() {

View File

@ -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`
}
}