X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FTwitchChatBot.php;h=a403b0b57b716ae488c1056e8f3e6d8be53573f8;hb=1b9629ce7f600b4aa9c9d51a281e514031871828;hp=aacc56fc11f2aa0e410787be739eab776136aacf;hpb=6a643908d58f26272c2095616514a140e7c0b4c0;p=alttp.git diff --git a/app/TwitchBot/TwitchChatBot.php b/app/TwitchBot/TwitchChatBot.php index aacc56f..a403b0b 100644 --- a/app/TwitchBot/TwitchChatBot.php +++ b/app/TwitchBot/TwitchChatBot.php @@ -3,6 +3,7 @@ namespace App\TwitchBot; use App\Models\Channel; +use App\Models\ChatBotLog; use App\Models\ChatLog; use Illuminate\Support\Arr; use Illuminate\Support\Str; @@ -74,8 +75,16 @@ class TwitchChatBot extends TwitchBot { $text = $this->contextualMsg($channel); if (!$text) $text = $this->randomChat($channel); if (!$text) return; + $actual_text = is_object($text) ? $text->text_content : $text; $this->tagChannelWrite($channel); - $this->sendIRCMessage(IRCMessage::privmsg($channel->twitch_chat, $text)); + $this->sendIRCMessage(IRCMessage::privmsg($channel->twitch_chat, $actual_text)); + $log = new ChatBotLog(); + $log->channel()->associate($channel); + if (is_object($text)) { + $log->origin()->associate($text); + } + $log->text = $actual_text; + $log->save(); } private function getNotes(Channel $channel) { @@ -85,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), @@ -123,7 +133,21 @@ class TwitchChatBot extends TwitchBot { } private function contextualMsg(Channel $channel) { - $last = $this->getNote($channel, 'last_special'); + 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 = [ 'gg' => 2, @@ -131,19 +155,23 @@ class TwitchChatBot extends TwitchBot { 'hi' => 2, 'hype' => 2, 'lol' => 2, + 'love' => 2, 'number' => 2, 'pog' => 2, 'o7' => 2, + 'wtf' => 2, ]; $time_quotas = [ - 'gg' => 300, + 'gg' => 600, 'gl' => 900, 'hi' => 60, 'hype' => 60, 'lol' => 60, + 'love' => 60, 'number' => 300, 'pog' => 60, 'o7' => 300, + 'wtf' => 60, ]; foreach ($classifications as $classification => $count) { if ($classification == $last) continue; @@ -162,10 +190,9 @@ class TwitchChatBot extends TwitchBot { } private function randomChat(Channel $channel) { - $line = $channel->queryChatlog() - ->whereIn('classification', ['hi', 'hype', 'lol', 'pog', 'unclassified']) + return $channel->queryChatlog() + ->whereNotIn('classification', ['gg', 'gl', 'number', 'o7']) ->first(); - return $line->text_content; } private function randomContextualNumber(Channel $channel) { @@ -183,6 +210,9 @@ class TwitchChatBot extends TwitchBot { } private function randomLaughter(Channel $channel) { + if (!random_int(0, 2)) { + return $channel->randomOfClass('lol'); + } return Arr::random([ ':tf:', '4Head', @@ -193,7 +223,6 @@ class TwitchChatBot extends TwitchBot { 'GunRun', 'heh', 'Hhhehehe', - 'HypeLUL', 'Jebaited', 'Jebasted', 'KEKW', @@ -212,13 +241,11 @@ class TwitchChatBot extends TwitchBot { 'SUBprise', 'xD', 'YouDontSay', - $channel->randomOfClass('lol'), ]); } private function randomMsg(Channel $channel) { - $line = $channel->queryChatlog()->first(); - return $line->text_content; + return $channel->queryChatlog()->first(); } private function randomWaitMsgs(Channel $channel) { @@ -233,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(); @@ -248,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); + } } } @@ -264,6 +314,19 @@ class TwitchChatBot extends TwitchBot { $this->notes[$channel->id]['last_special'][$classification] = time(); } + private function getLastSpecialSent(Channel $channel) { + $notes = $this->getNotes($channel); + $max_time = 0; + $max_classification = ''; + foreach ($notes['last_special'] as $classification => $time) { + if ($time > $max_time) { + $max_time = $time; + $max_classification = $classification; + } + } + return $max_classification; + } + private function getTimeSinceSpecial(Channel $channel, $classification) { $notes = $this->getNotes($channel); if (isset($notes['last_special'][$classification])) { @@ -291,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 = [];