]> git.localhorst.tv Git - alttp.git/commitdiff
add hth api key config
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 21 Sep 2025 21:28:44 +0000 (23:28 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 21 Sep 2025 21:28:44 +0000 (23:28 +0200)
.env.example
app/Console/Commands/SyncHTH.php
config/hth.php [new file with mode: 0644]

index 1a1fa72972984ec227523661eb3da2c611242475..146ce0d189b1d0734cf6f833a21f0422b319a7eb 100644 (file)
@@ -71,3 +71,5 @@ TWITCH_CLIENT_SECRET=
 TWITCH_REDIRECT_URI=
 
 GOOGLE_API_KEY=
+
+HTH_API_KEY=
index 875889de3cc3bf13a7eef4fb91d7a007c85a21fa..deab332b8c31a1852b418c66fd8a9dd77ab93467 100644 (file)
@@ -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 (file)
index 0000000..13432cf
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+return [
+       'api_key' => env('HTH_API_KEY', ''),
+];