]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/ChannelController.php
guessing game settings
[alttp.git] / app / Http / Controllers / ChannelController.php
index f1f3cdbeb4038da5cc8b12a7dc9b2b6060645ea2..cbd01104cb3e7cd497d42a44fd33206fdf214909 100644 (file)
@@ -110,4 +110,59 @@ class ChannelController extends Controller {
                return $channel->toJson();
        }
 
+       public function deleteCommand(Channel $channel, $command) {
+               $this->authorize('editRestream', $channel);
+               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();
+
+               return $channel->toJson();
+       }
+
 }