]> git.localhorst.tv Git - alttp.git/commitdiff
use classified messages
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 18 Feb 2024 16:04:35 +0000 (17:04 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 18 Feb 2024 16:04:35 +0000 (17:04 +0100)
app/TwitchBot/TwitchChatBot.php

index 470cb24f5f34fc717402051143213a6bc9842b42..8aac9d70bd66652eee0edad17161007732ad0586 100644 (file)
@@ -117,8 +117,7 @@ class TwitchChatBot extends TwitchBot {
                $notes = $this->getNotes($channel);
                $ggs = 0;
                foreach ($notes['latest_msgs'] as $text) {
-                       $rawText = strtolower(preg_replace('/[^\w]/', '', $text));
-                       if (Str::startsWith($rawText, 'gg') || Str::endsWith($rawText, 'gg')) {
+                       if (ChatLog::classify($text) == 'gg') {
                                ++$ggs;
                        }
                }
@@ -129,20 +128,40 @@ class TwitchChatBot extends TwitchBot {
                $notes = $this->getNotes($channel);
                $gls = 0;
                foreach ($notes['latest_msgs'] as $text) {
-                       $rawText = strtolower(preg_replace('/[^\w]/', '', $text));
-                       if (Str::contains($rawText, ['glgl', 'glhf', 'hfgl'])) {
+                       if (ChatLog::classify($text) == 'gl') {
                                ++$gls;
                        }
                }
                return $gls > 2;
        }
 
+       private function checkForGreeting(Channel $channel) {
+               $notes = $this->getNotes($channel);
+               $his = 0;
+               foreach ($notes['latest_msgs'] as $text) {
+                       if (ChatLog::classify($text) == 'hi') {
+                               ++$his;
+                       }
+               }
+               return $his > 2;
+       }
+
+       private function checkForHype(Channel $channel) {
+               $notes = $this->getNotes($channel);
+               $hypes = 0;
+               foreach ($notes['latest_msgs'] as $text) {
+                       if (ChatLog::classify($text) == 'hype') {
+                               ++$hypes;
+                       }
+               }
+               return $hypes > 2;
+       }
+
        private function checkForLaughter(Channel $channel) {
                $notes = $this->getNotes($channel);
                $lulz = 0;
                foreach ($notes['latest_msgs'] as $text) {
-                       $rawText = strtolower(preg_replace('/[^\w]/', '', $text));
-                       if (Str::contains($rawText, ['haha', 'kekw', 'lol', 'lul', 'xd'])) {
+                       if (ChatLog::classify($text) == 'lol') {
                                ++$lulz;
                        }
                }
@@ -160,11 +179,22 @@ class TwitchChatBot extends TwitchBot {
                return $numbers > 2;
        }
 
+       private function checkForPog(Channel $channel) {
+               $notes = $this->getNotes($channel);
+               $pogs = 0;
+               foreach ($notes['latest_msgs'] as $text) {
+                       if (ChatLog::classify($text) == 'pog') {
+                               ++$pogs;
+                       }
+               }
+               return $pogs > 2;
+       }
+
        private function contextualMsg(Channel $channel) {
                $last = $this->getNote($channel, 'last_special');
                if ($last != 'gg' && $this->checkForGG($channel)) {
                        $this->setNote($channel, 'last_special', 'gg');
-                       return $this->randomGG($channel);
+                       return $this->randomOfClass($channel, 'gg');
                }
                if ($last != 'number' && $this->checkForNumbers($channel)) {
                        $this->setNote($channel, 'last_special', 'number');
@@ -176,7 +206,19 @@ class TwitchChatBot extends TwitchBot {
                }
                if ($last != 'glhf' && $this->checkForGLHF($channel)) {
                        $this->setNote($channel, 'last_special', 'glhf');
-                       return $this->randomGLHF($channel);
+                       return $this->randomOfClass($channel, 'gl');
+               }
+               if ($last != 'hi' && $this->checkForGreeting($channel)) {
+                       $this->setNote($channel, 'last_special', 'hi');
+                       return $this->randomOfClass($channel, 'hi');
+               }
+               if ($last != 'hype' && $this->checkForHype($channel)) {
+                       $this->setNote($channel, 'last_special', 'hype');
+                       return $this->randomOfClass($channel, 'hype');
+               }
+               if ($last != 'pog' && $this->checkForPog($channel)) {
+                       $this->setNote($channel, 'last_special', 'pog');
+                       return $this->randomOfClass($channel, 'pog');
                }
                return false;
        }
@@ -206,18 +248,9 @@ class TwitchChatBot extends TwitchBot {
                return random_int($min, $max);
        }
 
-       private function randomGG(Channel $channel) {
-               $line = $this->queryChatlog($channel)
-                       ->where('text_content', 'LIKE', '%gg')
-                       ->whereRaw('LENGTH(`text_content`) < 30')
-                       ->first();
-               return $line->text_content;
-       }
-
-       private function randomGLHF(Channel $channel) {
+       private function randomOfClass(Channel $channel, $class) {
                $line = $this->queryChatlog($channel)
-                       ->where('text_content', 'LIKE', '%glhf%')
-                       ->whereRaw('LENGTH(`text_content`) < 30')
+                       ->where('classification', '=', $class)
                        ->first();
                return $line->text_content;
        }
@@ -252,6 +285,7 @@ class TwitchChatBot extends TwitchBot {
                        'SUBprise',
                        'xD',
                        'YouDontSay',
+                       $this->randomOfClass($channel, 'lol'),
                ]);
        }