+ private function getNotes(Channel $channel) {
+ if (!isset($this->notes[$channel->id])) {
+ $this->notes[$channel->id] = [
+ 'last_read' => 0,
+ 'last_special' => [],
+ 'last_write' => time(),
+ 'latest_msgs' => [],
+ 'queued_special' => false,
+ 'read_since_last_write' => 0,
+ 'wait_msgs' => $this->randomWaitMsgs($channel),
+ 'wait_time' => $this->randomWaitTime($channel),
+ ];
+ }
+ return $this->notes[$channel->id];
+ }
+
+ 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'])