X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FChannelController.php;h=121ae4e9ce9149fc2162001128dc2943d4a9a004;hb=f0d1a566f5afd76ab7a56b295b71d5756dfd2bc3;hp=78648af8dea8ece74e65e2987ea06a37e7479a58;hpb=167f986f468014e00d82fa2df8193f6be8dca19d;p=alttp.git diff --git a/app/Http/Controllers/ChannelController.php b/app/Http/Controllers/ChannelController.php index 78648af..121ae4e 100644 --- a/app/Http/Controllers/ChannelController.php +++ b/app/Http/Controllers/ChannelController.php @@ -13,12 +13,17 @@ class ChannelController extends Controller { public function search(Request $request) { $validatedData = $request->validate([ + 'id' => 'array', + 'id.*' => 'integer|numeric', 'joinable' => 'boolean|nullable', 'manageable' => 'boolean|nullable', 'phrase' => 'string|nullable', ]); $channels = Channel::query(); + if (!empty($validatedData['id'])) { + $channels = $channels->whereIn('id', $validatedData['id']); + } if (isset($validatedData['joinable']) && $validatedData['joinable']) { $channels = $channels->where('twitch_chat', '!=', ''); } @@ -49,22 +54,45 @@ class ChannelController extends Controller { throw new \Exception('channel has no twitch chat set'); } $validatedData = $request->validate([ + 'adlib' => 'boolean', 'bot_nick' => 'string', - 'text' => 'string|required', + 'category' => 'string', + 'text' => 'string', ]); $this->authorize('editRestream', $channel); $nick = empty($validatedData['bot_nick']) ? 'localhorsttv' : $validatedData['bot_nick']; - TwitchBotCommand::chat($channel->twitch_chat, $validatedData['text'], $request->user(), $nick); + if (isset($validatedData['adlib']) && $validatedData['adlib']) { + TwitchBotCommand::adlibChat($channel, $request->user()); + } else if (empty($validatedData['category'])) { + TwitchBotCommand::chat($channel->twitch_chat, $validatedData['text'], $request->user(), $nick); + } else { + TwitchBotCommand::randomChat($channel, $validatedData['category'], $request->user(), $nick); + } return $this->sendChannel($channel); } + public function chatBotLog(Request $request, Channel $channel) { + $this->authorize('editRestream', $channel); + $log = $channel->chat_bot_logs() + ->with(['origin', 'user']) + ->orderBy('created_at', 'DESC') + ->limit(150) + ->get(); + return $log->values()->toJson(); + } + public function chatSettings(Request $request, Channel $channel) { if (!$channel->twitch_chat) { throw new \Exception('channel has no twitch chat set'); } $validatedData = $request->validate([ + 'adlib' => 'integer|min:0|max:100', + 'language' => 'string|in:de,en,es,fr', + 'min_age' => 'integer|min:1', + 'respond' => 'string|in:50,no,yes', + 'source' => 'string|in:any,cat,catchan,chan', 'wait_msgs_min' => 'integer|min:1', - 'wait_msgs_max' => 'integer', + 'wait_msgs_max' => 'integer|min:1', 'wait_time_min' => 'integer', 'wait_time_max' => 'integer', ]); @@ -159,18 +187,7 @@ class ChannelController extends Controller { 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); - } + $msg = $channel->listGuessingWinners($winners); if (!empty($msg)) { TwitchBotCommand::chat($channel->twitch_chat, $msg); } @@ -216,6 +233,12 @@ class ChannelController extends Controller { ]; } + public function getGuessingGameLeaderboard(Channel $channel, $type) { + return [ + 'all' => $channel->getGuessingLeaderboard(), + ]; + } + public function getGuessingGameMonitor($key) { $channel = Channel::where('access_key', '=', $key)->firstOrFail(); @@ -239,7 +262,9 @@ class ChannelController extends Controller { $validatedData = $request->validate([ 'active_message' => 'string', 'cancel_message' => 'string', + 'close_winners_message' => 'string', 'invalid_solution_message' => 'string', + 'leaderboard_type' => 'string', 'no_winners_message' => 'string', 'not_active_message' => 'string', 'points_exact_first' => 'numeric|min:1|max:5',