]> git.localhorst.tv Git - alttp.git/commitdiff
queue user sync on discovery
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 20 Feb 2023 13:08:03 +0000 (14:08 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 20 Feb 2023 13:08:03 +0000 (14:08 +0100)
app/Console/Commands/SyncSpeedGaming.php
app/Models/DiscordBotCommand.php

index 4d2cb9cb27cb9a4a9195f21c93f3851238a6f9c2..13eb3a30e8b1724857ee4492e692962f21d9796f 100644 (file)
@@ -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']);
index ca8a0308ce0d96d37cd3d902b827cef327bb0925..7d7c3a88da96b6761a74e943474dd5ef1e6aaa78 100644 (file)
@@ -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);
        }