- 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) {
+ $last = $this->getNote($channel, 'last_special');
+ $classifications = $this->collectClassifications($channel);
+ $count_quotas = [
+ 'gg' => 2,
+ 'gl' => 2,
+ 'hi' => 2,
+ 'hype' => 2,
+ 'lol' => 2,
+ 'number' => 2,
+ 'pog' => 2,
+ 'o7' => 2,
+ ];
+ $time_quotas = [
+ 'gg' => 300,
+ 'gl' => 900,
+ 'hi' => 60,
+ 'hype' => 60,
+ 'lol' => 60,
+ 'number' => 300,
+ 'pog' => 60,
+ 'o7' => 300,
+ ];
+ 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);
+ if ($classification == 'number') {
+ return $this->randomContextualNumber($channel);
+ }
+ if ($classification == 'lol') {
+ return $this->randomLaughter($channel);
+ }
+ return $channel->randomOfClass($classification);
+ }
+ return false;
+ }
+
+ private function randomChat(Channel $channel) {
+ return $channel->queryChatlog()
+ ->whereIn('classification', ['hi', 'hype', 'lol', 'pog', 'unclassified'])