From 9bbd52a3b52020f57124e29c22982c6f2d5b1571 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 20 Feb 2023 14:08:03 +0100 Subject: [PATCH] queue user sync on discovery --- app/Console/Commands/SyncSpeedGaming.php | 11 +++++++++++ app/Models/DiscordBotCommand.php | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/Console/Commands/SyncSpeedGaming.php b/app/Console/Commands/SyncSpeedGaming.php index 4d2cb9c..13eb3a3 100644 --- a/app/Console/Commands/SyncSpeedGaming.php +++ b/app/Console/Commands/SyncSpeedGaming.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use App\Models\Channel; +use App\Models\DiscordBotCommand; use App\Models\Episode; use App\Models\EpisodePlayer; use App\Models\Event; @@ -179,6 +180,15 @@ class SyncSpeedGaming extends Command { $user = $this->getUserBySGPlayer($sgPlayer); if ($user) { $player->user()->associate($user); + if (empty($user->stream_link)) { + if (!empty($sgPlayer['publicStream'])) { + $user->stream_link = 'https://twitch.tv/'.strtolower($sgPlayer['publicStream']); + $user->save(); + } else if (!empty($sgPlayer['streamingFrom'])) { + $user->stream_link = 'https://twitch.tv/'.strtolower($sgPlayer['streamingFrom']); + $user->save(); + } + } } else { $player->user()->disassociate(); } @@ -195,6 +205,7 @@ class SyncSpeedGaming extends Command { if (!empty($player['discordId'])) { $user = User::find($player['discordId']); if ($user) return $user; + DiscordBotCommand::syncUser($player['discordId']); } if (!empty($player['discordTag'])) { $tag = explode('#', $player['discordTag']); diff --git a/app/Models/DiscordBotCommand.php b/app/Models/DiscordBotCommand.php index ca8a030..7d7c3a8 100644 --- a/app/Models/DiscordBotCommand.php +++ b/app/Models/DiscordBotCommand.php @@ -25,6 +25,16 @@ class DiscordBotCommand extends Model $cmd->save(); } + public static function syncUser($user_id) { + $cmd = new DiscordBotCommand(); + $cmd->command = 'sync-user'; + $cmd->parameters = [ + 'user' => $user_id, + ]; + $cmd->status = 'pending'; + $cmd->save(); + } + public function tournament() { return $this->belongsTo(Tournament::class); } -- 2.39.2