Adjust social generators for regional Splatfests

This commit is contained in:
Slushie
2023-11-10 13:56:16 +00:00
parent 574c3a9446
commit c0ae2c2c27
3 changed files with 92 additions and 12 deletions

View File

@@ -1,16 +1,35 @@
import StatusGenerator from "./StatusGenerator.mjs";
import Media from "../Media.mjs";
import { useUSSplatfestsStore } from '../../../src/stores/splatfests.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) {
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}`);
}
async getFestival() {
await this.preparePinia();
return useUSSplatfestsStore().recentFestival;
let store;
switch(this.region) {
case "NA": store = useUSSplatfestsStore(); break;
case "EU": store = useEUSplatfestsStore(); break;
case "JP": store = useJPSplatfestsStore(); break;
case "AP": store = useAPSplatfestsStore(); break;
}
return store.recentFestival;
}
async getDataTime() {
@@ -35,6 +54,21 @@ export default class SplatfestResultsStatus extends StatusGenerator
return `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;
}
return super.shouldPost(client);
}
async _getContentWrapper() {
let festival = await this.getFestival();

View File

@@ -1,17 +1,34 @@
import StatusGenerator from "./StatusGenerator.mjs";
import Media from "../Media.mjs";
import { useUSSplatfestsStore, STATUS_ACTIVE, STATUS_PAST } from '../../../src/stores/splatfests.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) {
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}`);
}
async getFestival() {
await this.preparePinia();
let store = useUSSplatfestsStore();
let store;
switch(this.region) {
case "NA": store = useUSSplatfestsStore(); break;
case "EU": store = useEUSplatfestsStore(); break;
case "JP": store = useJPSplatfestsStore(); break;
case "AP": store = useAPSplatfestsStore(); break;
}
return store.upcomingFestival
|| store.activeFestival
|| store.recentFestival;
@@ -52,6 +69,19 @@ 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;
}
let currentId = await this.getDataTime();
let cachedId = await this.lastPostCache(client).getData();
@@ -67,17 +97,27 @@ 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("/")})` : '';
switch (state) {
case 'upcoming':
return `You can now vote in the next Splatfest: ${festival.title} #splatfest #splatoon3`;
return `You can now vote in the next ${global ? 'global ' : ''}Splatfest: ${festival.title}${regionText} #splatfest #splatoon3`;
case 'upcoming:3d':
return `Reminder: The next Splatfest starts in 3 DAYS! ${festival.title} #splatfest #splatoon3`
return `Reminder: The next ${global ? 'global ' : ''}Splatfest starts in 3 DAYS! ${festival.title}${regionText} #splatfest #splatoon3`
case 'upcoming:1d':
return `Reminder: The next Splatfest starts in 24 HOURS! ${festival.title} #splatfest #splatoon3`
return `Reminder: The next ${global ? 'global ' : ''}Splatfest starts in 24 HOURS! ${festival.title}${regionText} #splatfest #splatoon3`
case 'active':
return `The Splatfest is NOW OPEN! ${festival.title} #splatfest #splatoon3`
return `The ${global ? 'global ' : ''}Splatfest is NOW OPEN! ${festival.title}${regionText} #splatfest #splatoon3`
case 'ended':
return `The Splatfest is now closed. Results are usually posted within 2 hours! #splatfest #splatoon3`
return `The ${global ? 'global ' : ''}Splatfest is now closed${regionText}. Results are usually posted within 2 hours! #splatfest #splatoon3`
}
}

View File

@@ -26,8 +26,14 @@ function defaultStatusGenerators() {
new SalmonRunStatus,
new SalmonRunUpcomingStatus,
new SalmonRunGearStatus,
new SplatfestStatus,
new SplatfestResultsStatus,
new SplatfestStatus("NA"),
new SplatfestStatus("EU"),
new SplatfestStatus("JP"),
new SplatfestStatus("AP"),
new SplatfestResultsStatus("NA"),
new SplatfestResultsStatus("EU"),
new SplatfestResultsStatus("JP"),
new SplatfestResultsStatus("AP"),
new EggstraWorkStatus,
new EggstraWorkUpcomingStatus,
];