namespace App\TwitchBot;
use App\Models\Channel;
+use App\Models\ChatBotLog;
use App\Models\ChatLog;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
$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) {
}
private function contextualMsg(Channel $channel) {
- $last = $this->getNote($channel, 'last_special');
+ $last = $this->getLastSpecialSent($channel);
$classifications = $this->collectClassifications($channel);
$count_quotas = [
'gg' => 2,
'hi' => 2,
'hype' => 2,
'lol' => 2,
+ 'love' => 2,
'number' => 2,
'pog' => 2,
'o7' => 2,
+ 'wtf' => 2,
];
$time_quotas = [
- 'gg' => 300,
+ 'gg' => 600,
'gl' => 900,
'hi' => 60,
'hype' => 60,
'lol' => 60,
+ 'love' => 60,
'number' => 300,
'pog' => 60,
'o7' => 300,
+ 'wtf' => 60,
];
foreach ($classifications as $classification => $count) {
if ($classification == $last) continue;
}
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) {
}
private function randomLaughter(Channel $channel) {
+ if (!random_int(0, 2)) {
+ return $channel->randomOfClass('lol');
+ }
return Arr::random([
':tf:',
'4Head',
'GunRun',
'heh',
'Hhhehehe',
- 'HypeLUL',
'Jebaited',
'Jebasted',
'KEKW',
'SUBprise',
'xD',
'YouDontSay',
- $channel->randomOfClass('lol'),
]);
}
private function randomMsg(Channel $channel) {
- $line = $channel->queryChatlog()->first();
- return $line->text_content;
+ return $channel->queryChatlog()->first();
}
private function randomWaitMsgs(Channel $channel) {
$this->notes[$channel->id]['last_special'][$classification] = time();
}
+ private function getLastSpecialSent(Channel $channel) {
+ $notes = $this->getNotes($channel);
+ $max_time = 0;
+ $max_classification = '';
+ foreach ($notes['last_special'] as $classification => $time) {
+ if ($time > $max_time) {
+ $max_time = $time;
+ $max_classification = $classification;
+ }
+ }
+ return $max_classification;
+ }
+
private function getTimeSinceSpecial(Channel $channel, $classification) {
$notes = $this->getNotes($channel);
if (isset($notes['last_special'][$classification])) {