X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FChannel.php;h=f50c267eb8a3cae89bfbba84bada33f682a86862;hb=1a863c3ecfa04eacf7df3c5bce71c12244e4625b;hp=8af6a7d43e201e191651a4ab9b28fc7c11642ec5;hpb=147c5f43c5d41fa18e82edb6651fe5a37c789353;p=alttp.git diff --git a/app/Models/Channel.php b/app/Models/Channel.php index 8af6a7d..f50c267 100644 --- a/app/Models/Channel.php +++ b/app/Models/Channel.php @@ -32,20 +32,34 @@ class Channel extends Model { } public function randomOfClass($class) { + if (is_array($class)) { + return $this->queryChatlog() + ->whereIn('classification', $class) + ->first(); + } return $this->queryChatlog() ->where('classification', '=', $class) ->first(); } 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() { @@ -208,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; }