use App\Models\Channel;
use App\Models\ChatBotLog;
+use App\Models\ChatLib;
use App\Models\ChatLog;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
$this->updateChannels();
$this->startTimer();
$this->listenCommands();
+ $this->chatlib = new ChatLib();
+ $this->chatlib->loadFrom('de');
}
public function joinChannels() {
$this->tagChannelRead($channel, $msg);
}
+ public function getChatlibDatabase(Channel $channel) {
+ return $this->chatlib;
+ }
+
private function startTimer() {
$this->getLoop()->addPeriodicTimer(1, function () {
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;
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);
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') {
private $channels;
private $notes = [];
+ private $chatlib;
}