+ 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) {
+ $rawText = strtolower(preg_replace('/[^\w]/', '', $text));
+ if (Str::startsWith($rawText, 'gg') || Str::endsWith($rawText, 'gg')) {
+ ++$ggs;
+ }
+ }
+ return $ggs > 2;
+ }
+
+ private function checkForGLHF(Channel $channel) {
+ $notes = $this->getNotes($channel);
+ $gls = 0;
+ foreach ($notes['latest_msgs'] as $text) {
+ $rawText = strtolower(preg_replace('/[^\w]/', '', $text));
+ if (Str::contains($rawText, ['glgl', 'glhf', 'hfgl'])) {
+ ++$gls;
+ }
+ }
+ return $gls > 2;
+ }
+
+ private function checkForLaughter(Channel $channel) {
+ $notes = $this->getNotes($channel);
+ $lulz = 0;
+ foreach ($notes['latest_msgs'] as $text) {
+ $rawText = strtolower(preg_replace('/[^\w]/', '', $text));
+ if (Str::contains($rawText, ['haha', 'kekw', 'lol', 'lul', 'xd'])) {
+ ++$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 contextualMsg(Channel $channel) {
+ $last = $this->getNote($channel, 'last_special');
+ if ($last != 'gg' && $this->checkForGG($channel)) {
+ $this->setNote($channel, 'last_special', 'gg');
+ return $this->randomGG($channel);
+ }
+ 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->randomGLHF($channel);
+ }
+ return false;
+ }
+
+ private function queryChatlog(Channel $channel) {
+ return ChatLog::where('type', '=', 'chat')