X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FChannel.php;h=f50c267eb8a3cae89bfbba84bada33f682a86862;hb=76e2a3da33fc0cccbdb8864416bbb2a8684987ab;hp=5c7ae70c0e95ebfec714052becfc28580dc1f354;hpb=1d3c8c6a96fc45d839f0e3719baca790059d189f;p=alttp.git diff --git a/app/Models/Channel.php b/app/Models/Channel.php index 5c7ae70..f50c267 100644 --- a/app/Models/Channel.php +++ b/app/Models/Channel.php @@ -32,21 +32,34 @@ class Channel extends Model { } public function randomOfClass($class) { - $line = $this->queryChatlog() + if (is_array($class)) { + return $this->queryChatlog() + ->whereIn('classification', $class) + ->first(); + } + return $this->queryChatlog() ->where('classification', '=', $class) ->first(); - return $line ? $line->text_content : ''; } public function queryChatlog() { - return ChatLog::where('type', '=', 'chat') + $min_age = $this->getChatSetting('min_age', 1); + $query = ChatLog::where('type', '=', 'chat') ->where('banned', '=', false) - ->where('created_at', '<', now()->sub(1, 'day')) + ->where('created_at', '<', now()->sub($min_age, 'day')) ->where(function ($query) { $query->whereNull('detected_language'); $query->orWhereIn('detected_language', $this->getPreferredLanguages()); }) ->inRandomOrder(); + $source = $this->getChatSetting('source', 'any'); + if (in_array($source, ['catchan', 'chan'])) { + $query->where('channel_id', $this->id); + } + if (in_array($source, ['cat', 'catchan'])) { + $query->where('twitch_category', $this->twitch_category); + } + return $query; } public function getPreferredLanguages() { @@ -209,7 +222,7 @@ class Channel extends Model { $transformed = $this->transformGuess($solution); if ($this->guessing_type == 'gtbk') { $int_solution = intval($transformed); - return is_numeric($transformed) && $int_solution > 0 && $int_solution < 23; + return is_numeric($transformed) && $int_solution >= 0 && $int_solution <= 23; } return false; } @@ -241,6 +254,10 @@ class Channel extends Model { return Arr::join($entries, ', ', ' and '); } + public function chat_bot_logs() { + return $this->hasMany(ChatBotLog::class); + } + public function crews() { return $this->hasMany(ChannelCrew::class); }