- private function randomMsg(Channel $channel) {
- $line = ChatLog::where('type', '=', 'chat')
- ->where('banned', '=', false)
- ->where('created_at', '<', now()->sub(1, 'day'))
- ->where(function ($query) use ($channel) {
- $query->whereNull('detected_language');
- $query->orWhereIn('detected_language', $channel->languages);
- })
- ->inRandomOrder()
+ private function getNote(Channel $channel, $name, $default = null) {
+ $notes = $this->getNotes($channel);
+ if (array_key_exists($name, $notes)) {
+ return $notes[$name];
+ }
+ return $default;
+ }
+
+ private function setNote(Channel $channel, $name, $value) {
+ $this->getNotes($channel);
+ $this->notes[$channel->id][$name] = $value;
+ }
+
+ private function collectClassifications(Channel $channel) {
+ $classifications = [];
+ $notes = $this->getNotes($channel);
+ foreach ($notes['latest_msgs'] as $msg) {
+ $classification = $msg->classify();
+ if ($classification == 'unclassified') continue;
+ if (isset($classifications[$classification])) {
+ ++$classifications[$classification];
+ } else {
+ $classifications[$classification] = 1;
+ }
+ }
+ arsort($classifications);
+ return $classifications;
+ }
+
+ private function contextualMsg(Channel $channel) {
+ if ($this->hasQueuedSpecial($channel)) {
+ $classification = $this->getQueuedSpecial($channel);
+ if (is_string($classification)) {
+ $this->tagChannelSpecialSent($channel, $classification);
+ }
+ $this->clearQueuedSpecial($channel);
+ return $this->getRandomOfClass($channel, $classification);
+ }
+ $latest_msg = $this->getLatestMessage($channel);
+ if ($latest_msg->classify() == 'question') {
+ $response = $latest_msg->getResponseCategory();
+ return $this->getRandomOfClass($channel, $response);
+ }
+ $last = $this->getLastSpecialSent($channel);
+ $classifications = $this->collectClassifications($channel);
+ $count_quotas = [
+ 'gg' => 2,
+ 'gl' => 2,
+ 'hi' => 2,
+ 'hype' => 2,
+ 'lol' => 2,
+ 'love' => 2,
+ 'number' => 2,
+ 'pog' => 2,
+ 'o7' => 2,
+ 'wtf' => 2,
+ ];
+ $time_quotas = [
+ '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;
+ if (!isset($count_quotas[$classification]) || $count < $count_quotas[$classification]) continue;
+ if (!isset($time_quotas[$classification]) || $this->getTimeSinceSpecial($channel, $classification) < $time_quotas[$classification]) continue;
+ $this->tagChannelSpecialSent($channel, $classification);
+ $reaction = $this->getChimeInReaction($channel, $classification);
+ return $this->getRandomOfClass($channel, $reaction);
+ }
+ return false;
+ }
+
+ private function randomChat(Channel $channel) {
+ return $channel->queryChatlog()
+ ->whereNotIn('classification', ['gg', 'gl', 'number', 'o7'])