From: Daniel Karbach Date: Fri, 5 Apr 2024 19:45:47 +0000 (+0200) Subject: chat bot config X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=cf210ddda8ff5336feee10f733b022a72d906238;p=alttp.git chat bot config --- diff --git a/app/Http/Controllers/ChannelController.php b/app/Http/Controllers/ChannelController.php index c47a406..b72742f 100644 --- a/app/Http/Controllers/ChannelController.php +++ b/app/Http/Controllers/ChannelController.php @@ -68,6 +68,8 @@ class ChannelController extends Controller { throw new \Exception('channel has no twitch chat set'); } $validatedData = $request->validate([ + 'language' => 'string|in:de,en,es,fr', + 'respond' => 'string|in:50,no,yes', 'wait_msgs_min' => 'integer|min:1', 'wait_msgs_max' => 'integer', 'wait_time_min' => 'integer', diff --git a/app/TwitchBot/TwitchChatBot.php b/app/TwitchBot/TwitchChatBot.php index da4cc04..03d9a38 100644 --- a/app/TwitchBot/TwitchChatBot.php +++ b/app/TwitchBot/TwitchChatBot.php @@ -244,7 +244,7 @@ class TwitchChatBot extends TwitchBot { ->where('created_at', '<', now()->sub(1, 'day')) ->where(function ($query) use ($channel) { $query->whereNull('detected_language'); - $query->orWhereIn('detected_language', $channel->languages); + $query->orWhereIn('detected_language', $this->getPreferredLanguages($channel)); }) ->inRandomOrder(); } @@ -338,7 +338,7 @@ class TwitchChatBot extends TwitchBot { array_shift($this->notes[$channel->id]['latest_msgs']); } } - if ($this->isDirectedAtMe($msg->getText())) { + if ($this->isDirectedAtMe($msg->getText()) && $this->shouldRespond($channel)) { $this->notes[$channel->id]['wait_msgs'] = 0; $this->notes[$channel->id]['wait_time'] = 0; } @@ -352,6 +352,17 @@ class TwitchChatBot extends TwitchBot { $this->notes[$channel->id]['wait_time'] = $this->randomWaitTime($channel); } + private function getPreferredLanguages(Channel $channel) { + $setting = $this->getChatSetting($channel, 'language'); + if ($setting) { + return [$setting]; + } + if (!empty($channel->languages)) { + return $channel->languages; + } + return ['de']; + } + private function isDirectedAtMe($raw_text) { $text = strtolower($raw_text); if (strpos($text, 'horstie') !== false) { @@ -360,6 +371,17 @@ class TwitchChatBot extends TwitchBot { return false; } + private function shouldRespond(Channel $channel) { + $setting = $this->getChatSetting($channel, 'respond', 'yes'); + if ($setting == 'yes') { + return true; + } + if ($setting == '50') { + return random_int(0, 1); + } + return false; + } + private $channels; private $notes = []; diff --git a/resources/js/components/twitch-bot/ChatSettingsForm.js b/resources/js/components/twitch-bot/ChatSettingsForm.js index d9c03d7..4d36a31 100644 --- a/resources/js/components/twitch-bot/ChatSettingsForm.js +++ b/resources/js/components/twitch-bot/ChatSettingsForm.js @@ -85,6 +85,48 @@ const ChatSettingsForm = ({ } + + {t('twitchBot.language')} + + {['de', 'en', 'es', 'fr'].map(lang => + + )} + + {touched.language && errors.language ? + + {t(errors.language)} + + : null} + + + {t('twitchBot.respond')} + + {['yes', '50', 'no'].map(value => + + )} + + {touched.respond && errors.respond ? + + {t(errors.respond)} + + : null} +