Added support for different Splatfest Pro and Open rotations.
This commit is contained in:
parent
fd03da959a
commit
b755646252
3 changed files with 49 additions and 21 deletions
|
@ -2,7 +2,16 @@
|
||||||
namespace Satori;
|
namespace Satori;
|
||||||
|
|
||||||
final class SHttp {
|
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 = curl_init($url);
|
||||||
curl_setopt_array($curl, [
|
curl_setopt_array($curl, [
|
||||||
CURLOPT_AUTOREFERER => true,
|
CURLOPT_AUTOREFERER => true,
|
||||||
|
@ -18,7 +27,7 @@ final class SHttp {
|
||||||
CURLOPT_CONNECTTIMEOUT => 2,
|
CURLOPT_CONNECTTIMEOUT => 2,
|
||||||
CURLOPT_TIMEOUT => 5,
|
CURLOPT_TIMEOUT => 5,
|
||||||
CURLOPT_USERAGENT => sprintf('Satori/%s (+https://fii.moe/satori)', SAT_VERSION),
|
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);
|
$response = json_decode(curl_exec($curl), true);
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
@ -26,7 +35,7 @@ final class SHttp {
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getJsonCached(string $url): mixed {
|
public static function getJsonCached(string $url, array $headers = []): mixed {
|
||||||
return SFileCache::for15mins($url, fn() => self::getJson($url));
|
return SFileCache::for15mins($url, fn() => self::getJson($url, $headers));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,11 +55,11 @@ final class SatoriContext {
|
||||||
public function createRouting(): RoutingContext {
|
public function createRouting(): RoutingContext {
|
||||||
$routingCtx = new 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 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 Splatoon\SplatoonRoutes($this->createSplatoon()));
|
||||||
|
$routingCtx->register(new Translation\TranslateRoutes($this->createTranslation()));
|
||||||
|
|
||||||
return $routingCtx;
|
return $routingCtx;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,9 +104,10 @@ class Splatoon3Game implements ISplatoonGame, ISplatoonHasFestivals, ISplatoonHa
|
||||||
'coop' => 'coop',
|
'coop' => 'coop',
|
||||||
'eggstra' => 'eggstra',
|
'eggstra' => 'eggstra',
|
||||||
'bigrun' => 'bigrun',
|
'bigrun' => 'bigrun',
|
||||||
'fest' => 'fest',
|
'fest' => 'bankara',
|
||||||
'splatfest' => 'fest',
|
'splatfest' => 'bankara',
|
||||||
'festival' => 'fest',
|
'festival' => 'bankara',
|
||||||
|
'pro' => 'series',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function isValidScheduleFilter(string $filter): bool {
|
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) {
|
foreach($raw['festSchedules']['nodes'] as $info) {
|
||||||
if(!empty($info['festMatchSettings'])) {
|
if(empty($info['festMatchSettings']))
|
||||||
$modes[] = new Splatoon3GameMode('fest', 'Splatfest Battle', 0xFF71717A);
|
continue;
|
||||||
break;
|
|
||||||
}
|
if($includeRankedSeries && !empty($info['festMatchSettings'][0])) {
|
||||||
|
$includeRankedSeries = false;
|
||||||
|
$variants[] = new Splatoon3GameModeVariant('PRO', 'Pro', 0xFF603BFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($raw['currentFest']['tricolorStage']))
|
if($includeRankedOpen && !empty($info['festMatchSettings'][1])) {
|
||||||
$modes[] = new Splatoon3GameMode('tricolor', 'Tricolor Battle', 0xFF71717A);
|
$includeRankedOpen = false;
|
||||||
|
$variants[] = new Splatoon3GameModeVariant('OPEN', 'Open', 0xFF603BFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$includeRankedSeries && !$includeRankedOpen)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)) {
|
if(array_key_exists('coopGroupingSchedule', $raw)) {
|
||||||
$coop = $raw['coopGroupingSchedule'];
|
$coop = $raw['coopGroupingSchedule'];
|
||||||
|
|
||||||
|
@ -297,17 +313,20 @@ class Splatoon3Game implements ISplatoonGame, ISplatoonHasFestivals, ISplatoonHa
|
||||||
$schedules[] = new Splatoon3ScheduleEntryVsLeague($locale, $info);
|
$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) {
|
foreach($raw['festSchedules']['nodes'] as $info) {
|
||||||
if(empty($info['festMatchSettings']))
|
if(empty($info['festMatchSettings']))
|
||||||
continue;
|
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']))
|
if($includeRanked && !empty($raw['currentFest']['tricolorStage']))
|
||||||
$schedules[] = new Splatoon3ScheduleEntryVsTricolor($locale, $raw['currentFest']['tricolorStage']);
|
$schedules[] = new Splatoon3ScheduleEntryVsTricolor($locale, $raw['currentFest']['tricolorStage']);
|
||||||
}
|
|
||||||
|
|
||||||
if(array_key_exists('coopGroupingSchedule', $raw)) {
|
if(array_key_exists('coopGroupingSchedule', $raw)) {
|
||||||
$coop = $raw['coopGroupingSchedule'];
|
$coop = $raw['coopGroupingSchedule'];
|
||||||
|
|
Reference in a new issue