]> git.localhorst.tv Git - alttp.git/blobdiff - app/TwitchBot/TwitchChatBot.php
try to respond more appropriately
[alttp.git] / app / TwitchBot / TwitchChatBot.php
index ebf2b94af14d2da6175f578a55f759c1cd9fd515..a403b0b57b716ae488c1056e8f3e6d8be53573f8 100644 (file)
@@ -94,6 +94,7 @@ class TwitchChatBot extends TwitchBot {
                                'last_special' => [],
                                'last_write' => time(),
                                'latest_msgs' => [],
+                               'queued_special' => false,
                                'read_since_last_write' => 0,
                                'wait_msgs' => $this->randomWaitMsgs($channel),
                                'wait_time' => $this->randomWaitTime($channel),
@@ -132,6 +133,20 @@ class TwitchChatBot extends TwitchBot {
        }
 
        private function contextualMsg(Channel $channel) {
+               if ($this->hasQueuedSpecial($channel)) {
+                       $classification = $this->getQueuedSpecial($channel);
+                       if (is_string($classification)) {
+                               $this->tagChannelSpecialSent($channel, $classification);
+                       }
+                       $this->clearQueuedSpecial($channel);
+                       if ($classification == 'number') {
+                               return $this->randomContextualNumber($channel);
+                       }
+                       if ($classification == 'lol') {
+                               return $this->randomLaughter($channel);
+                       }
+                       return $channel->randomOfClass($classification);
+               }
                $last = $this->getLastSpecialSent($channel);
                $classifications = $this->collectClassifications($channel);
                $count_quotas = [
@@ -176,7 +191,7 @@ class TwitchChatBot extends TwitchBot {
 
        private function randomChat(Channel $channel) {
                return $channel->queryChatlog()
-                       ->whereNotIn('classification', ['gg', 'gl', 'o7'])
+                       ->whereNotIn('classification', ['gg', 'gl', 'number', 'o7'])
                        ->first();
        }
 
@@ -245,6 +260,25 @@ class TwitchChatBot extends TwitchBot {
                return random_int($min, $max);
        }
 
+       private function queueSpecial(Channel $channel, $classification) {
+               $this->getNotes($channel);
+               $this->notes[$channel->id]['queued_special'] = $classification;
+       }
+
+       private function hasQueuedSpecial(Channel $channel) {
+               return !!$this->getQueuedSpecial($channel);
+       }
+
+       private function getQueuedSpecial(Channel $channel) {
+               $notes = $this->getNotes($channel);
+               return $notes['queued_special'];
+       }
+
+       private function clearQueuedSpecial(Channel $channel) {
+               $this->getNotes($channel);
+               $this->notes[$channel->id]['queued_special'] = false;
+       }
+
        private function tagChannelRead(Channel $channel, IRCMessage $msg) {
                $this->getNotes($channel);
                $this->notes[$channel->id]['last_read'] = time();
@@ -260,6 +294,10 @@ class TwitchChatBot extends TwitchBot {
                if ($this->isDirectedAtMe($msg->getText()) && $this->shouldRespond($channel)) {
                        $this->notes[$channel->id]['wait_msgs'] = 0;
                        $this->notes[$channel->id]['wait_time'] = 0;
+                       $response = $this->getResponseTo($tokenized);
+                       if ($response) {
+                               $this->queueSpecial($channel, $response);
+                       }
                }
        }
 
@@ -316,6 +354,28 @@ class TwitchChatBot extends TwitchBot {
                return false;
        }
 
+       private function getResponseTo(TokenizedMessage $msg) {
+               switch ($msg->classify()) {
+                       case 'gg':
+                               return ['love', 'eyes', 'thx', 'pog', 'kappa'];
+                       case 'gl':
+                               return ['love', 'eyes', 'thx'];
+                       case 'hi':
+                               return ['hi', 'love', 'eyes', 'hype', 'pog'];
+                       case 'kappa':
+                               return ['kappa', 'lol', 'eyes'];
+                       case 'love':
+                               return ['hi', 'love', 'eyes', 'thx'];
+                       case 'question':
+                               return ['yes', 'no', 'kappa', 'lol', 'wtf', 'number'];
+                       case 'rage':
+                               return ['kappa', 'lol', 'rage'];
+                       case 'wtf':
+                               return ['kappa', 'lol', 'rage'];
+               }
+               return false;
+       }
+
        private $channels;
        private $notes = [];