+ $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 $this->sendChannel($channel);
+ }
+
+ 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 $this->sendChannel($channel);
+ }
+
+ 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 $this->sendChannel($channel);
+ }
+
+ public function controlGuessingGame(Request $request, Channel $channel, $name) {
+ $this->authorize('editRestream', $channel);
+
+ $validatedData = $request->validate([
+ 'action' => 'required|in:cancel,solve,start,stop',
+ 'solution' => '',
+ ]);
+
+ switch ($validatedData['action']) {
+ case 'cancel':
+ $channel->clearGuessing();
+ $msg = $channel->getGuessingSetting('cancel_message');
+ if (!empty($msg)) {
+ TwitchBotCommand::chat($channel->twitch_chat, $msg);
+ }
+ break;
+ case 'solve':
+ if ($channel->hasActiveGuessing() && $channel->isValidGuess($validatedData['solution'])) {
+ $winners = $channel->solveGuessing($validatedData['solution']);
+ $names = [];
+ foreach ($winners as $winner) {
+ if ($winner->score > 0) {
+ $names[] = $winner->uname;
+ }
+ }
+ if (empty($names)) {
+ $msg = $channel->getGuessingSetting('no_winners_message');
+ } else {
+ $msg = $channel->getGuessingSetting('winners_message');
+ $msg = str_replace('{names}', $channel->listAnd($names), $msg);
+ }
+ if (!empty($msg)) {
+ TwitchBotCommand::chat($channel->twitch_chat, $msg);
+ }
+ $channel->clearGuessing();
+ }
+ break;
+ case 'start':
+ if (!$channel->hasActiveGuessing()) {
+ $channel->startGuessing($name);
+ $msg = $channel->getGuessingSetting('start_message');
+ if (!empty($msg)) {
+ TwitchBotCommand::chat($channel->twitch_chat, $msg);
+ }
+ }
+ break;
+ case 'stop':
+ if ($channel->hasActiveGuessing()) {
+ $channel->stopGuessing();
+ $msg = $channel->getGuessingSetting('stop_message');
+ if (!empty($msg)) {
+ TwitchBotCommand::chat($channel->twitch_chat, $msg);
+ }
+ }
+ break;
+ }
+
+ return $this->sendChannel($channel);
+ }
+
+ public function getGuessingGame(Channel $channel, $name) {