From: Daniel Karbach Date: Sun, 8 Oct 2023 14:14:03 +0000 (+0200) Subject: associate user with twitch command X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=4b0f87a8b0683579c53c68f35b18e5d08c30b3b9;p=alttp.git associate user with twitch command --- 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(); }