]> git.localhorst.tv Git - alttp.git/commitdiff
add context to adlibs
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 28 Jun 2024 14:49:20 +0000 (16:49 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 28 Jun 2024 14:49:20 +0000 (16:49 +0200)
app/TwitchBot/TokenizedMessage.php
app/TwitchBot/TwitchChatBot.php

index 72817c1dbc6066556f77e134684e74137d64f863..f218e7ae9de89e8482bb0a2b6d0b1c92ff8eaab3 100644 (file)
@@ -50,6 +50,11 @@ class TokenizedMessage {
        }
 
 
+       public function getText() {
+               return $this->text;
+       }
+
+
        public function contains($text) {
                return Str::contains($this->text, $text);
        }
@@ -286,7 +291,7 @@ class TokenizedMessage {
                                $this->classification = 'cmd';
                        } else if ($this->isShort() && ($this->hasTokenThatStartsOrEndsWith(['gg']) || $this->hasEmoteThatEndsWith(['gg']))) {
                                $this->classification = 'gg';
-                       } else if ($this->isShort() && $this->containsRaw(['glgl', 'glhf', 'goodluck', 'hfgl', 'vielglück'])) {
+                       } else if ($this->isShort() && ($this->containsRaw(['glgl', 'glhf', 'goodluck', 'hfgl', 'vielglück']) || $this->hasToken('gl'))) {
                                $this->classification = 'gl';
                        } else if ($this->hasToken(['danke', 'thanks', 'thx', 'ty']) && !$this->hasToken(['nah', 'nee', 'nein', 'no'])) {
                                $this->classification = 'thx';
@@ -348,9 +353,9 @@ class TokenizedMessage {
                                        $this->hasConsecutiveTokens(['how', 'much']) ||
                                        $this->hasConsecutiveTokens(['wie', 'viele'])
                                ) {
-                                       return ['yes', 'no', 'kappa', 'lol', 'wtf', 'number'];
+                                       return ['yes', 'no', 'kappa', 'wtf', 'number'];
                                }
-                               return ['yes', 'no', 'kappa', 'lol', 'wtf'];
+                               return ['yes', 'no', 'kappa', 'wtf'];
                        case 'rage':
                                return ['kappa', 'lol', 'rage'];
                        case 'wtf':
index 6ec517e93f62ba55926e40b5a6bfa15303a3c9a7..700de25bfb86bff91542b0f95f98f43bb4af9f80 100644 (file)
@@ -80,7 +80,7 @@ class TwitchChatBot extends TwitchBot {
                        return;
                }
                $text = $this->contextualMsg($channel);
-               if ($this->shouldAdlib($channel)) {
+               if (!$text && $this->shouldAdlib($channel)) {
                        $this->performAdlib($channel);
                        return;
                }
@@ -258,7 +258,8 @@ class TwitchChatBot extends TwitchBot {
 
        private function performAdlib(Channel $channel) {
                $db = $this->getChatlibDatabase($channel);
-               $text = $db->generate();
+               $latest_msg = $this->getLatestMessage($channel);
+               $text = $db->generate($latest_msg->getText());
                $this->tagChannelWrite($channel);
                $this->sendIRCMessage(IRCMessage::privmsg($channel->twitch_chat, $text));
                $log = new ChatBotLog();
@@ -306,12 +307,10 @@ class TwitchChatBot extends TwitchBot {
 
                $tokenized = $msg->tokenize();
                if (!ChatLog::isKnownBot($msg->nick) && !$tokenized->isSpammy()) {
-                       $this->notes[$channel->id]['latest_msgs'][] = $tokenized;
-                       if (count($this->notes[$channel->id]['latest_msgs']) > 10) {
-                               array_shift($this->notes[$channel->id]['latest_msgs']);
-                       }
+                       $this->noteChannelMessage($channel, $tokenized);
                }
                if ($this->isDirectedAtMe($msg->getText()) && $this->shouldRespond($channel)) {
+                       $this->noteChannelMessage($channel, $tokenized);
                        $this->notes[$channel->id]['wait_msgs'] = 0;
                        $this->notes[$channel->id]['wait_time'] = 0;
                        $response = $tokenized->getResponseCategory();
@@ -321,6 +320,13 @@ class TwitchChatBot extends TwitchBot {
                }
        }
 
+       private function noteChannelMessage(Channel $channel, TokenizedMessage $tokenized) {
+               $this->notes[$channel->id]['latest_msgs'][] = $tokenized;
+               if (count($this->notes[$channel->id]['latest_msgs']) > 10) {
+                       array_shift($this->notes[$channel->id]['latest_msgs']);
+               }
+       }
+
        private function tagChannelWrite(Channel $channel) {
                $this->getNotes($channel);
                $this->notes[$channel->id]['last_write'] = time();
@@ -335,7 +341,7 @@ class TwitchChatBot extends TwitchBot {
        }
 
        private function getLatestMessage(Channel $channel) {
-               $this->getNotes($channel);
+               $notes = $this->getNotes($channel);
                if (!empty($notes['latest_msgs'])) {
                        return $notes['latest_msgs'][count($notes['latest_msgs']) - 1];
                }