X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FTwitchChatBot.php;fp=app%2FTwitchBot%2FTwitchChatBot.php;h=03d9a38c88b402b327532e290249bb8d986f8990;hb=cf210ddda8ff5336feee10f733b022a72d906238;hp=da4cc041aff1314e7f2f3ca75226ea686cca50e6;hpb=d2bba770693e1f85479725eb176818c416be414d;p=alttp.git 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 = [];