From 4b8475936f9c0f0379d2dee4e1440f4445682715 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 7 May 2024 15:10:01 +0200 Subject: [PATCH] configurable min age and message source --- app/Http/Controllers/ChannelController.php | 4 +- app/Models/Channel.php | 13 +++++- .../components/twitch-bot/ChatSettingsForm.js | 42 +++++++++++++++++++ resources/js/i18n/de.js | 8 ++++ resources/js/i18n/en.js | 8 ++++ 5 files changed, 72 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ChannelController.php b/app/Http/Controllers/ChannelController.php index f9cf0d2..026b9aa 100644 --- a/app/Http/Controllers/ChannelController.php +++ b/app/Http/Controllers/ChannelController.php @@ -84,9 +84,11 @@ class ChannelController extends Controller { } $validatedData = $request->validate([ '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', ]); diff --git a/app/Models/Channel.php b/app/Models/Channel.php index 8045a41..c6dfb6a 100644 --- a/app/Models/Channel.php +++ b/app/Models/Channel.php @@ -43,14 +43,23 @@ class Channel extends Model { } public function queryChatlog() { - return ChatLog::where('type', '=', 'chat') + $min_age = $this->getChatSetting('min_age', 1); + $query = ChatLog::where('type', '=', 'chat') ->where('banned', '=', false) - ->where('created_at', '<', now()->sub(1, 'day')) + ->where('created_at', '<', now()->sub($min_age, 'day')) ->where(function ($query) { $query->whereNull('detected_language'); $query->orWhereIn('detected_language', $this->getPreferredLanguages()); }) ->inRandomOrder(); + $source = $this->getChatSetting('source', 'any'); + if (in_array($source, ['catchan', 'chan'])) { + $query->where('channel_id', $this->id); + } + if (in_array($source, ['cat', 'catchan'])) { + $query->where('twitch_category', $this->twitch_category); + } + return $query; } public function getPreferredLanguages() { diff --git a/resources/js/components/twitch-bot/ChatSettingsForm.js b/resources/js/components/twitch-bot/ChatSettingsForm.js index 4d36a31..9f6a183 100644 --- a/resources/js/components/twitch-bot/ChatSettingsForm.js +++ b/resources/js/components/twitch-bot/ChatSettingsForm.js @@ -127,6 +127,39 @@ const ChatSettingsForm = ({ : null} + + {t('twitchBot.chatMinAge')} + + + + {t('twitchBot.chatSource')} + + {['any', 'cat', 'chan', 'catchan'].map(value => + + )} + + {touched.respond && errors.respond ? + + {t(errors.respond)} + + : null} +