From 6a752625ddb1f6670a0f63eeaa93e5bdc5432583 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 21 Sep 2025 23:28:44 +0200 Subject: [PATCH] add hth api key config --- .env.example | 2 ++ app/Console/Commands/SyncHTH.php | 19 +++++++++---------- config/hth.php | 5 +++++ 3 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 config/hth.php diff --git a/.env.example b/.env.example index 1a1fa72..146ce0d 100644 --- a/.env.example +++ b/.env.example @@ -71,3 +71,5 @@ TWITCH_CLIENT_SECRET= TWITCH_REDIRECT_URI= GOOGLE_API_KEY= + +HTH_API_KEY= diff --git a/app/Console/Commands/SyncHTH.php b/app/Console/Commands/SyncHTH.php index 875889d..deab332 100644 --- a/app/Console/Commands/SyncHTH.php +++ b/app/Console/Commands/SyncHTH.php @@ -2,13 +2,10 @@ namespace App\Console\Commands; -use App\Models\Channel; use App\Models\DiscordBotCommand; use App\Models\Episode; -use App\Models\EpisodeCrew; use App\Models\EpisodePlayer; use App\Models\Event; -use App\Models\Organization; use App\Models\User; use Carbon\Carbon; use Illuminate\Console\Command; @@ -56,13 +53,15 @@ class SyncHTH extends Command { return 0; } - private function syncEvent(Event $event) { + private function syncEvent(Event $event): void { $hthHandle = substr($event->external_schedule, 4); $parts = explode('/', $hthHandle); $hthSeries = $parts[0]; $hthEvent = $parts[1]; - $this->line('series: "'.$hthSeries.'", evnet: "'.$hthEvent.'"'); - $hthSchedule = HTTP::post('https://hth.zeldaspeedruns.com/api/v1/graphql', [ + $this->line('series: "'.$hthSeries.'", event: "'.$hthEvent.'"'); + $hthSchedule = Http::withHeaders([ + 'X-API-Key', config('hth.api_key') + ])->post('https://hth.zeldaspeedruns.com/api/v1/graphql', [ 'operation_name' => 'my_schedule', 'variables' => [ 'my_series' => $hthSeries, @@ -106,7 +105,7 @@ class SyncHTH extends Command { } } - private function syncSchedule(Event $event, $hthEntry) { + private function syncSchedule(Event $event, $hthEntry): void { $ext_id = 'hth:'.$hthEntry['id']; $episode = Episode::firstWhere('ext_id', '=', $ext_id); if (!$hthEntry['start']) { @@ -148,7 +147,7 @@ class SyncHTH extends Command { } } - private function purgePlayers(Episode $episode, $hthEntry) { + private function purgePlayers(Episode $episode, $hthEntry): void { $ext_ids = []; foreach ($hthEntry['teams'] as $hthTeam) { foreach ($hthTeam['members'] as $hthPlayer) { @@ -158,7 +157,7 @@ class SyncHTH extends Command { $episode->players()->whereNotIn('ext_id', $ext_ids)->delete(); } - private function syncPlayer(Episode $episode, $hthTeam, $hthPlayer) { + private function syncPlayer(Episode $episode, $hthTeam, $hthPlayer): void { $ext_id = 'hth:'.$hthPlayer['user']['id']; $player = $episode->players()->firstWhere('ext_id', '=', $ext_id); if (!$player) { @@ -178,7 +177,7 @@ class SyncHTH extends Command { $player->save(); } - private function getUserByHTHPlayer($player) { + private function getUserByHTHPlayer($player): User|null { if (!empty($player['user']['discordId'])) { $user = User::find($player['user']['discordId']); if ($user) { diff --git a/config/hth.php b/config/hth.php new file mode 100644 index 0000000..13432cf --- /dev/null +++ b/config/hth.php @@ -0,0 +1,5 @@ + env('HTH_API_KEY', ''), +]; -- 2.47.2