X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FTwitchChatBot.php;h=831bf5ca4560acf7f09f909079d4dcbea787c324;hb=249e06be11d0f7778d99956c87d4f0a8ac7e69f7;hp=470cb24f5f34fc717402051143213a6bc9842b42;hpb=532dea7c62f3619a04cd8d7aa895f8db1f3f98d2;p=alttp.git diff --git a/app/TwitchBot/TwitchChatBot.php b/app/TwitchBot/TwitchChatBot.php index 470cb24..831bf5c 100644 --- a/app/TwitchBot/TwitchChatBot.php +++ b/app/TwitchBot/TwitchChatBot.php @@ -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,33 @@ 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 checkForSalute(Channel $channel) { + $notes = $this->getNotes($channel); + $o7s = 0; + foreach ($notes['latest_msgs'] as $text) { + if (ChatLog::classify($text) == 'o7') { + ++$o7s; + } + } + return $o7s > 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 +217,23 @@ 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'); + } + if ($last != 'o7' && $this->checkForSalute($channel)) { + $this->setNote($channel, 'last_special', 'o7'); + return $this->randomOfClass($channel, 'o7'); } return false; } @@ -192,6 +249,13 @@ class TwitchChatBot extends TwitchBot { ->inRandomOrder(); } + private function randomChat(Channel $channel) { + $line = $this->queryChatlog($channel) + ->whereIn('classification', ['hi', 'hype', 'lol', 'pog', 'unclassified']) + ->first(); + return $line->text_content; + } + private function randomContextualNumber(Channel $channel) { $notes = $this->getNotes($channel); $min = 100000; @@ -206,18 +270,9 @@ class TwitchChatBot extends TwitchBot { return random_int($min, $max); } - private function randomGG(Channel $channel) { + private function randomOfClass(Channel $channel, $class) { $line = $this->queryChatlog($channel) - ->where('text_content', 'LIKE', '%gg') - ->whereRaw('LENGTH(`text_content`) < 30') - ->first(); - return $line->text_content; - } - - private function randomGLHF(Channel $channel) { - $line = $this->queryChatlog($channel) - ->where('text_content', 'LIKE', '%glhf%') - ->whereRaw('LENGTH(`text_content`) < 30') + ->where('classification', '=', $class) ->first(); return $line->text_content; } @@ -252,6 +307,7 @@ class TwitchChatBot extends TwitchBot { 'SUBprise', 'xD', 'YouDontSay', + $this->randomOfClass($channel, 'lol'), ]); } @@ -276,9 +332,11 @@ class TwitchChatBot extends TwitchBot { $this->getNotes($channel); $this->notes[$channel->id]['last_read'] = time(); ++$this->notes[$channel->id]['read_since_last_write']; - $this->notes[$channel->id]['latest_msgs'][] = $msg->getText(); - if (count($this->notes[$channel->id]['latest_msgs']) > 10) { - array_shift($this->notes[$channel->id]['latest_msgs']); + if (!ChatLog::isKnownBot($msg->nick) && !ChatLog::spammyText($msg->getText())) { + $this->notes[$channel->id]['latest_msgs'][] = $msg->getText(); + if (count($this->notes[$channel->id]['latest_msgs']) > 10) { + array_shift($this->notes[$channel->id]['latest_msgs']); + } } }