+ 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 checkForGG(Channel $channel) {
+ $notes = $this->getNotes($channel);
+ $ggs = 0;
+ foreach ($notes['latest_msgs'] as $text) {
+ if (ChatLog::classify($text) == 'gg') {
+ ++$ggs;
+ }
+ }
+ return $ggs > 2;
+ }
+
+ private function checkForGLHF(Channel $channel) {
+ $notes = $this->getNotes($channel);
+ $gls = 0;
+ foreach ($notes['latest_msgs'] as $text) {
+ if (ChatLog::classify($text) == 'gl') {
+ ++$gls;
+ }
+ }
+ return $gls > 2;
+ }
+
+ private function checkForGreeting(Channel $channel) {
+ $notes = $this->getNotes($channel);
+ $his = 0;
+ foreach ($notes['latest_msgs'] as $text) {
+ if (ChatLog::classify($text) == 'hi') {
+ ++$his;
+ }
+ }
+ return $his > 2;
+ }
+
+ private function checkForHype(Channel $channel) {
+ $notes = $this->getNotes($channel);
+ $hypes = 0;
+ foreach ($notes['latest_msgs'] as $text) {
+ if (ChatLog::classify($text) == 'hype') {
+ ++$hypes;
+ }
+ }
+ return $hypes > 2;
+ }
+
+ private function checkForLaughter(Channel $channel) {
+ $notes = $this->getNotes($channel);
+ $lulz = 0;
+ foreach ($notes['latest_msgs'] as $text) {
+ if (ChatLog::classify($text) == 'lol') {
+ ++$lulz;
+ }
+ }
+ return $lulz > 2;
+ }
+
+ private function checkForNumbers(Channel $channel) {
+ $notes = $this->getNotes($channel);
+ $numbers = 0;
+ foreach ($notes['latest_msgs'] as $text) {
+ if (is_numeric(trim($text))) {
+ ++$numbers;
+ }
+ }
+ return $numbers > 2;
+ }
+
+ private function checkForPog(Channel $channel) {
+ $notes = $this->getNotes($channel);
+ $pogs = 0;
+ foreach ($notes['latest_msgs'] as $text) {
+ if (ChatLog::classify($text) == 'pog') {
+ ++$pogs;
+ }
+ }
+ return $pogs > 2;
+ }
+
+ private function checkForSalute(Channel $channel) {
+ $notes = $this->getNotes($channel);
+ $o7s = 0;
+ foreach ($notes['latest_msgs'] as $text) {
+ if (ChatLog::classify($text) == 'o7') {
+ ++$o7s;
+ }
+ }
+ return $o7s > 2;
+ }
+
+ private function contextualMsg(Channel $channel) {
+ $last = $this->getNote($channel, 'last_special');
+ if ($last != 'gg' && $this->checkForGG($channel)) {
+ $this->setNote($channel, 'last_special', 'gg');
+ return $this->randomOfClass($channel, 'gg');
+ }
+ if ($last != 'number' && $this->checkForNumbers($channel)) {
+ $this->setNote($channel, 'last_special', 'number');
+ return $this->randomContextualNumber($channel);
+ }
+ if ($last != 'lol' && $this->checkForLaughter($channel)) {
+ $this->setNote($channel, 'last_special', 'lol');
+ return $this->randomLaughter($channel);
+ }
+ if ($last != 'glhf' && $this->checkForGLHF($channel)) {
+ $this->setNote($channel, 'last_special', 'glhf');
+ return $this->randomOfClass($channel, 'gl');
+ }
+ if ($last != 'hi' && $this->checkForGreeting($channel)) {
+ $this->setNote($channel, 'last_special', 'hi');
+ return $this->randomOfClass($channel, 'hi');
+ }
+ if ($last != 'hype' && $this->checkForHype($channel)) {
+ $this->setNote($channel, 'last_special', 'hype');
+ return $this->randomOfClass($channel, 'hype');
+ }
+ if ($last != 'pog' && $this->checkForPog($channel)) {
+ $this->setNote($channel, 'last_special', 'pog');
+ return $this->randomOfClass($channel, 'pog');
+ }
+ if ($last != 'o7' && $this->checkForSalute($channel)) {
+ $this->setNote($channel, 'last_special', 'o7');
+ return $this->randomOfClass($channel, 'o7');
+ }
+ return false;
+ }
+
+ private function queryChatlog(Channel $channel) {
+ return ChatLog::where('type', '=', 'chat')