X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FTwitchChatBot.php;h=92894262f3b108d42826f76238dca6c909146a94;hb=8645b77ea2dc402f0265e1c8022ba18302506ca1;hp=ebf2b94af14d2da6175f578a55f759c1cd9fd515;hpb=a45390fd150b79014088b343591dc701dfe89c13;p=alttp.git diff --git a/app/TwitchBot/TwitchChatBot.php b/app/TwitchBot/TwitchChatBot.php index ebf2b94..9289426 100644 --- a/app/TwitchBot/TwitchChatBot.php +++ b/app/TwitchBot/TwitchChatBot.php @@ -82,6 +82,9 @@ class TwitchChatBot extends TwitchBot { $log->channel()->associate($channel); if (is_object($text)) { $log->origin()->associate($text); + $log->category = $text->classification; + } else { + $log->category = $this->getLastSpecialSent($channel); } $log->text = $actual_text; $log->save(); @@ -94,6 +97,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 +136,19 @@ 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); + return $this->getRandomOfClass($channel, $classification); + } + $latest_msg = $this->getLatestMessage($channel); + if ($latest_msg->classify() == 'question') { + $response = $latest_msg->getResponseCategory(); + return $this->getRandomOfClass($channel, $response); + } $last = $this->getLastSpecialSent($channel); $classifications = $this->collectClassifications($channel); $count_quotas = [ @@ -163,20 +180,15 @@ class TwitchChatBot extends TwitchBot { if (!isset($count_quotas[$classification]) || $count < $count_quotas[$classification]) continue; if (!isset($time_quotas[$classification]) || $this->getTimeSinceSpecial($channel, $classification) < $time_quotas[$classification]) continue; $this->tagChannelSpecialSent($channel, $classification); - if ($classification == 'number') { - return $this->randomContextualNumber($channel); - } - if ($classification == 'lol') { - return $this->randomLaughter($channel); - } - return $channel->randomOfClass($classification); + $reaction = $this->getChimeInReaction($channel, $classification); + return $this->getRandomOfClass($channel, $reaction); } return false; } private function randomChat(Channel $channel) { return $channel->queryChatlog() - ->whereNotIn('classification', ['gg', 'gl', 'o7']) + ->whereNotIn('classification', ['gg', 'gl', 'number', 'o7']) ->first(); } @@ -245,6 +257,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 +291,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 = $tokenized->getResponseCategory(); + if ($response) { + $this->queueSpecial($channel, $response); + } } } @@ -276,6 +311,14 @@ class TwitchChatBot extends TwitchBot { $this->notes[$channel->id]['last_special'][$classification] = time(); } + private function getLatestMessage(Channel $channel) { + $this->getNotes($channel); + if (!empty($notes['latest_msgs'])) { + return $notes['latest_msgs'][count($notes['latest_msgs']) - 1]; + } + return TokenizedMessage::fromString(''); + } + private function getLastSpecialSent(Channel $channel) { $notes = $this->getNotes($channel); $max_time = 0; @@ -316,6 +359,32 @@ class TwitchChatBot extends TwitchBot { return false; } + private function getRandomOfClass(Channel $channel, $classification) { + if ($classification == 'number') { + return $this->randomContextualNumber($channel); + } + if ($classification == 'lol') { + return $this->randomLaughter($channel); + } + return $channel->randomOfClass($classification); + } + + private function getChimeInReaction(Channel $channel, $classification) { + switch ($classification) { + case 'hi': + return ['hi', 'love']; + case 'hype': + return ['hype', 'love', 'pog']; + case 'lol': + return ['kappa', 'lol']; + case 'pog': + return ['hype', 'pog']; + case 'wtf': + return ['lol', 'wtf']; + } + return $classification; + } + private $channels; private $notes = [];