X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FChannelController.php;h=cbd01104cb3e7cd497d42a44fd33206fdf214909;hb=93f50820771a0333b169f76f74727239cf0cb286;hp=904cb8ff81ebc0833fc7912aeae96a10edae2ef5;hpb=e10222af705e3475fcea6e0b17d1c9984a62db26;p=alttp.git diff --git a/app/Http/Controllers/ChannelController.php b/app/Http/Controllers/ChannelController.php index 904cb8f..cbd0110 100644 --- a/app/Http/Controllers/ChannelController.php +++ b/app/Http/Controllers/ChannelController.php @@ -42,14 +42,52 @@ class ChannelController extends Controller { return $channel->toJson(); } + public function chat(Request $request, Channel $channel) { + if (!$channel->twitch_chat) { + throw new \Exception('channel has no twitch chat set'); + } + $validatedData = $request->validate([ + 'bot_nick' => 'string', + 'text' => 'string|required', + ]); + $this->authorize('editRestream', $channel); + $nick = empty($validatedData['bot_nick']) ? 'localhorsttv' : $validatedData['bot_nick']; + TwitchBotCommand::chat($channel->twitch_chat, $validatedData['text'], $request->user(), $nick); + return $channel->toJson(); + } + + public function chatSettings(Request $request, Channel $channel) { + if (!$channel->twitch_chat) { + throw new \Exception('channel has no twitch chat set'); + } + $validatedData = $request->validate([ + 'wait_msgs_min' => 'integer|min:1', + 'wait_msgs_max' => 'integer', + 'wait_time_min' => 'integer', + 'wait_time_max' => 'integer', + ]); + $this->authorize('editRestream', $channel); + $channel->chat_settings = $validatedData; + $channel->save(); + return $channel->toJson(); + } + public function join(Request $request, Channel $channel) { if (!$channel->twitch_chat) { throw new \Exception('channel has no twitch chat set'); } + $validatedData = $request->validate([ + 'bot_nick' => 'string', + ]); $this->authorize('editRestream', $channel); - $channel->join = true; + $nick = empty($validatedData['bot_nick']) ? 'localhorsttv' : $validatedData['bot_nick']; + if ($nick == 'localhorsttv') { + $channel->join = true; + } else if ($nick == 'horstiebot') { + $channel->chat = true; + } $channel->save(); - TwitchBotCommand::join($channel->twitch_chat); + TwitchBotCommand::join($channel->twitch_chat, $request->user(), $nick); return $channel->toJson(); } @@ -57,10 +95,73 @@ class ChannelController extends Controller { if (!$channel->twitch_chat) { throw new \Exception('channel has no twitch chat set'); } + $validatedData = $request->validate([ + 'bot_nick' => 'string', + ]); + $this->authorize('editRestream', $channel); + $nick = empty($validatedData['bot_nick']) ? 'localhorsttv' : $validatedData['bot_nick']; + if ($nick == 'localhorsttv') { + $channel->join = false; + } else if ($nick == 'horstiebot') { + $channel->chat = false; + } + $channel->save(); + TwitchBotCommand::part($channel->twitch_chat, $request->user(), $nick); + return $channel->toJson(); + } + + public function deleteCommand(Channel $channel, $command) { $this->authorize('editRestream', $channel); - $channel->join = false; + if (isset($channel->chat_commands[$command])) { + $cmds = $channel->chat_commands; + unset($cmds[$command]); + $channel->chat_commands = $cmds; + $channel->save(); + } + return $channel->toJson(); + } + + public function saveCommand(Request $request, Channel $channel, $command) { + $this->authorize('editRestream', $channel); + + $validatedData = $request->validate([ + 'command' => 'string', + 'restrict' => 'string', + 'type' => 'string', + ]); + + $cmds = $channel->chat_commands; + $cmds[$command] = $validatedData; + $channel->chat_commands = $cmds; + $channel->save(); + + return $channel->toJson(); + } + + public function saveGuessingGame(Request $request, Channel $channel, $name) { + $this->authorize('editRestream', $channel); + + $validatedData = $request->validate([ + 'active_message' => 'string', + 'cancel_message' => 'string', + 'invalid_solution_message' => 'string', + 'no_winners_message' => 'string', + 'not_active_message' => 'string', + 'points_exact_first' => 'numeric|min:1|max:5', + 'points_exact_other' => 'numeric|min:0|max:5', + 'points_close_first' => 'numeric|min:0|max:5', + 'points_close_min' => 'integer|min:0', + 'points_close_other' => 'numeric|min:0|max:5', + 'start_message' => 'string', + 'stop_message' => 'string', + 'winners_message' => 'string', + ]); + + $settings = $channel->guessing_settings; + $settings[$name] = $validatedData; + $channel->guessing_settings = $settings; $channel->save(); - TwitchBotCommand::part($channel->twitch_chat); + return $channel->toJson(); }