X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FTwitchChatBot.php;h=6ec517e93f62ba55926e40b5a6bfa15303a3c9a7;hb=f0d1a566f5afd76ab7a56b295b71d5756dfd2bc3;hp=442173d8c60c82228d66ffdd52e2b1ff5744ef07;hpb=907f392f8d2fbadb3f53a277cc90ae080da6d476;p=alttp.git diff --git a/app/TwitchBot/TwitchChatBot.php b/app/TwitchBot/TwitchChatBot.php index 442173d..6ec517e 100644 --- a/app/TwitchBot/TwitchChatBot.php +++ b/app/TwitchBot/TwitchChatBot.php @@ -4,6 +4,7 @@ namespace App\TwitchBot; use App\Models\Channel; use App\Models\ChatBotLog; +use App\Models\ChatLib; use App\Models\ChatLog; use Illuminate\Support\Arr; use Illuminate\Support\Str; @@ -15,6 +16,8 @@ class TwitchChatBot extends TwitchBot { $this->updateChannels(); $this->startTimer(); $this->listenCommands(); + $this->chatlib = new ChatLib(); + $this->chatlib->loadFrom('de'); } public function joinChannels() { @@ -43,6 +46,10 @@ class TwitchChatBot extends TwitchBot { $this->tagChannelRead($channel, $msg); } + public function getChatlibDatabase(Channel $channel) { + return $this->chatlib; + } + private function startTimer() { $this->getLoop()->addPeriodicTimer(1, function () { @@ -73,6 +80,10 @@ class TwitchChatBot extends TwitchBot { return; } $text = $this->contextualMsg($channel); + if ($this->shouldAdlib($channel)) { + $this->performAdlib($channel); + return; + } if (!$text) $text = $this->randomChat($channel); if (!$text) return; $actual_text = is_object($text) ? $text->text_content : $text; @@ -82,6 +93,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(); @@ -242,6 +256,18 @@ class TwitchChatBot extends TwitchBot { return $channel->queryChatlog()->first(); } + private function performAdlib(Channel $channel) { + $db = $this->getChatlibDatabase($channel); + $text = $db->generate(); + $this->tagChannelWrite($channel); + $this->sendIRCMessage(IRCMessage::privmsg($channel->twitch_chat, $text)); + $log = new ChatBotLog(); + $log->channel()->associate($channel); + $log->category = 'adlib'; + $log->text = $text; + $log->save(); + } + private function randomWaitMsgs(Channel $channel) { $min = $channel->getChatSetting('wait_msgs_min', 1); $max = $channel->getChatSetting('wait_msgs_max', 10); @@ -345,6 +371,17 @@ class TwitchChatBot extends TwitchBot { return false; } + private function shouldAdlib(Channel $channel) { + $setting = $channel->getChatSetting('adlib', 50); + if ($setting == 0) { + return false; + } + if ($setting == 100) { + return true; + } + return random_int(0, 100) <= $setting; + } + private function shouldRespond(Channel $channel) { $setting = $channel->getChatSetting('respond', 'yes'); if ($setting == 'yes') { @@ -384,5 +421,6 @@ class TwitchChatBot extends TwitchBot { private $channels; private $notes = []; + private $chatlib; }