X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FTwitchChatBot.php;h=6ec517e93f62ba55926e40b5a6bfa15303a3c9a7;hb=f0d1a566f5afd76ab7a56b295b71d5756dfd2bc3;hp=92894262f3b108d42826f76238dca6c909146a94;hpb=a45648fa8ecf7712c7fd00eb2b93e862b5264f04;p=alttp.git diff --git a/app/TwitchBot/TwitchChatBot.php b/app/TwitchBot/TwitchChatBot.php index 9289426..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; @@ -245,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); @@ -348,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') { @@ -387,5 +421,6 @@ class TwitchChatBot extends TwitchBot { private $channels; private $notes = []; + private $chatlib; }