]> git.localhorst.tv Git - alttp.git/blobdiff - app/Models/Channel.php
chat adlib prototype
[alttp.git] / app / Models / Channel.php
index 8af6a7d43e201e191651a4ab9b28fc7c11642ec5..f50c267eb8a3cae89bfbba84bada33f682a86862 100644 (file)
@@ -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;
        }