X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FTwitchChatBot.php;h=90a718d25b36875591e44b7ea9baf8d33fba69f6;hb=ebdf8e5f6761de2abd85b01096a67dee62d7d4aa;hp=aacc56fc11f2aa0e410787be739eab776136aacf;hpb=6a643908d58f26272c2095616514a140e7c0b4c0;p=alttp.git diff --git a/app/TwitchBot/TwitchChatBot.php b/app/TwitchBot/TwitchChatBot.php index aacc56f..90a718d 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) { @@ -162,10 +171,9 @@ class TwitchChatBot extends TwitchBot { } private function randomChat(Channel $channel) { - $line = $channel->queryChatlog() + return $channel->queryChatlog() ->whereIn('classification', ['hi', 'hype', 'lol', 'pog', 'unclassified']) ->first(); - return $line->text_content; } private function randomContextualNumber(Channel $channel) { @@ -217,8 +225,7 @@ class TwitchChatBot extends TwitchBot { } private function randomMsg(Channel $channel) { - $line = $channel->queryChatlog()->first(); - return $line->text_content; + return $channel->queryChatlog()->first(); } private function randomWaitMsgs(Channel $channel) {