]> git.localhorst.tv Git - alttp.git/blobdiff - app/TwitchBot/TwitchChatBot.php
chat bot config
[alttp.git] / app / TwitchBot / TwitchChatBot.php
index da4cc041aff1314e7f2f3ca75226ea686cca50e6..03d9a38c88b402b327532e290249bb8d986f8990 100644 (file)
@@ -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 = [];