From 4b0f87a8b0683579c53c68f35b18e5d08c30b3b9 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 8 Oct 2023 16:14:03 +0200 Subject: [PATCH] associate user with twitch command --- app/Http/Controllers/ChannelController.php | 4 ++-- app/Models/TwitchBotCommand.php | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ChannelController.php b/app/Http/Controllers/ChannelController.php index 904cb8f..f6840f8 100644 --- a/app/Http/Controllers/ChannelController.php +++ b/app/Http/Controllers/ChannelController.php @@ -49,7 +49,7 @@ class ChannelController extends Controller { $this->authorize('editRestream', $channel); $channel->join = true; $channel->save(); - TwitchBotCommand::join($channel->twitch_chat); + TwitchBotCommand::join($channel->twitch_chat, $request->user()); return $channel->toJson(); } @@ -60,7 +60,7 @@ class ChannelController extends Controller { $this->authorize('editRestream', $channel); $channel->join = false; $channel->save(); - TwitchBotCommand::part($channel->twitch_chat); + TwitchBotCommand::part($channel->twitch_chat, $request->user()); return $channel->toJson(); } diff --git a/app/Models/TwitchBotCommand.php b/app/Models/TwitchBotCommand.php index f2b35e3..94462e4 100644 --- a/app/Models/TwitchBotCommand.php +++ b/app/Models/TwitchBotCommand.php @@ -11,23 +11,25 @@ class TwitchBotCommand extends Model { use HasFactory; - public static function join($channel) { + public static function join($channel, User $user = null) { $cmd = new TwitchBotCommand(); $cmd->command = 'join'; $cmd->parameters = [ 'channel' => $channel, ]; $cmd->status = 'pending'; + $cmd->user()->associate($user); $cmd->save(); } - public static function part($channel) { + public static function part($channel, User $user = null) { $cmd = new TwitchBotCommand(); $cmd->command = 'part'; $cmd->parameters = [ 'channel' => $channel, ]; $cmd->status = 'pending'; + $cmd->user()->associate($user); $cmd->save(); } -- 2.39.2