From b755646252962a4a4ae34ac0697262c9a2a29ab8 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 13 Jul 2024 13:38:07 +0000 Subject: [PATCH] Added support for different Splatfest Pro and Open rotations. --- src/SHttp.php | 17 +++++++-- src/SatoriContext.php | 6 +-- src/Splatoon/Splatoon3/Splatoon3Game.php | 47 +++++++++++++++++------- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/SHttp.php b/src/SHttp.php index 10ec289..e1fa31b 100644 --- a/src/SHttp.php +++ b/src/SHttp.php @@ -2,7 +2,16 @@ namespace Satori; final class SHttp { - public static function getJson(string $url): mixed { + public static function getJson(string $url, array $headers = []): mixed { + // this isn't case insensitive so please promise me that + // you'll always use proper casing for header names ok???? + if(!array_key_exists('Accept', $headers)) + $headers['Accept'] = 'application/json'; + + $rawHeaders = []; + foreach($headers as $name => $value) + $rawHeaders[] = sprintf('%s: %s', $name, $value); + $curl = curl_init($url); curl_setopt_array($curl, [ CURLOPT_AUTOREFERER => true, @@ -18,7 +27,7 @@ final class SHttp { CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_TIMEOUT => 5, CURLOPT_USERAGENT => sprintf('Satori/%s (+https://fii.moe/satori)', SAT_VERSION), - CURLOPT_HTTPHEADER => ['Accept: application/json'], + CURLOPT_HTTPHEADER => $rawHeaders, ]); $response = json_decode(curl_exec($curl), true); curl_close($curl); @@ -26,7 +35,7 @@ final class SHttp { return $response; } - public static function getJsonCached(string $url): mixed { - return SFileCache::for15mins($url, fn() => self::getJson($url)); + public static function getJsonCached(string $url, array $headers = []): mixed { + return SFileCache::for15mins($url, fn() => self::getJson($url, $headers)); } } diff --git a/src/SatoriContext.php b/src/SatoriContext.php index cd646ca..f1a02c0 100644 --- a/src/SatoriContext.php +++ b/src/SatoriContext.php @@ -55,11 +55,11 @@ final class SatoriContext { public function createRouting(): RoutingContext { $routingCtx = new RoutingContext; - $routingCtx->register(new ExRate\ExRateRoutes($this->createExRates())); - $routingCtx->register(new Dictionary\DictionaryRoutes($this->createDictionary())); - $routingCtx->register(new Translation\TranslateRoutes($this->createTranslation())); $routingCtx->register(new Booru\BooruRoutes($this->createBooru())); + $routingCtx->register(new Dictionary\DictionaryRoutes($this->createDictionary())); + $routingCtx->register(new ExRate\ExRateRoutes($this->createExRates())); $routingCtx->register(new Splatoon\SplatoonRoutes($this->createSplatoon())); + $routingCtx->register(new Translation\TranslateRoutes($this->createTranslation())); return $routingCtx; } diff --git a/src/Splatoon/Splatoon3/Splatoon3Game.php b/src/Splatoon/Splatoon3/Splatoon3Game.php index c241479..4a12ee7 100644 --- a/src/Splatoon/Splatoon3/Splatoon3Game.php +++ b/src/Splatoon/Splatoon3/Splatoon3Game.php @@ -104,9 +104,10 @@ class Splatoon3Game implements ISplatoonGame, ISplatoonHasFestivals, ISplatoonHa 'coop' => 'coop', 'eggstra' => 'eggstra', 'bigrun' => 'bigrun', - 'fest' => 'fest', - 'splatfest' => 'fest', - 'festival' => 'fest', + 'fest' => 'bankara', + 'splatfest' => 'bankara', + 'festival' => 'bankara', + 'pro' => 'series', ]; public function isValidScheduleFilter(string $filter): bool { @@ -195,18 +196,33 @@ class Splatoon3Game implements ISplatoonGame, ISplatoonHasFestivals, ISplatoonHa } } - if(in_array('fest', $filters) && array_key_exists('festSchedules', $raw) && !empty($raw['festSchedules']['nodes'])) { + if($includeRanked && array_key_exists('festSchedules', $raw) && !empty($raw['festSchedules']['nodes'])) { + $variants = []; foreach($raw['festSchedules']['nodes'] as $info) { - if(!empty($info['festMatchSettings'])) { - $modes[] = new Splatoon3GameMode('fest', 'Splatfest Battle', 0xFF71717A); - break; + if(empty($info['festMatchSettings'])) + continue; + + if($includeRankedSeries && !empty($info['festMatchSettings'][0])) { + $includeRankedSeries = false; + $variants[] = new Splatoon3GameModeVariant('PRO', 'Pro', 0xFF603BFF); } + + if($includeRankedOpen && !empty($info['festMatchSettings'][1])) { + $includeRankedOpen = false; + $variants[] = new Splatoon3GameModeVariant('OPEN', 'Open', 0xFF603BFF); + } + + if(!$includeRankedSeries && !$includeRankedOpen) + break; } - if(!empty($raw['currentFest']['tricolorStage'])) - $modes[] = new Splatoon3GameMode('tricolor', 'Tricolor Battle', 0xFF71717A); + if(!empty($variants)) + $modes[] = new Splatoon3GameMode('fest', 'Splatfest Battle', 0xFFCFF622, $variants); } + if($includeRanked && !empty($raw['currentFest']['tricolorStage'])) + $modes[] = new Splatoon3GameMode('tricolor', 'Tricolor Battle', 0xFF71717A); + if(array_key_exists('coopGroupingSchedule', $raw)) { $coop = $raw['coopGroupingSchedule']; @@ -297,17 +313,20 @@ class Splatoon3Game implements ISplatoonGame, ISplatoonHasFestivals, ISplatoonHa $schedules[] = new Splatoon3ScheduleEntryVsLeague($locale, $info); } - if(in_array('fest', $filters) && array_key_exists('festSchedules', $raw) && !empty($raw['festSchedules']['nodes'])) { + if($includeRanked && array_key_exists('festSchedules', $raw) && !empty($raw['festSchedules']['nodes'])) foreach($raw['festSchedules']['nodes'] as $info) { if(empty($info['festMatchSettings'])) continue; - $schedules[] = new Splatoon3ScheduleEntryVs($locale, 'fest', '', $info, $info['festMatchSettings']); + if($includeRankedSeries && !empty($info['festMatchSettings'][0])) + $schedules[] = new Splatoon3ScheduleEntryVs($locale, 'fest', 'PRO', $info, $info['festMatchSettings'][0]); + + if($includeRankedOpen && !empty($info['festMatchSettings'][1])) + $schedules[] = new Splatoon3ScheduleEntryVs($locale, 'fest', 'OPEN', $info, $info['festMatchSettings'][1]); } - if(!empty($raw['currentFest']['tricolorStage'])) - $schedules[] = new Splatoon3ScheduleEntryVsTricolor($locale, $raw['currentFest']['tricolorStage']); - } + if($includeRanked && !empty($raw['currentFest']['tricolorStage'])) + $schedules[] = new Splatoon3ScheduleEntryVsTricolor($locale, $raw['currentFest']['tricolorStage']); if(array_key_exists('coopGroupingSchedule', $raw)) { $coop = $raw['coopGroupingSchedule'];