]> git.localhorst.tv Git - alttp.git/blobdiff - app/Models/Channel.php
chat bot protocol ui
[alttp.git] / app / Models / Channel.php
index bf3b98bc2b231c384a3079613e551514a7435c02..8af6a7d43e201e191651a4ab9b28fc7c11642ec5 100644 (file)
@@ -31,9 +31,45 @@ class Channel extends Model {
                        ->first();
        }
 
+       public function randomOfClass($class) {
+               return $this->queryChatlog()
+                       ->where('classification', '=', $class)
+                       ->first();
+       }
+
+       public function queryChatlog() {
+               return ChatLog::where('type', '=', 'chat')
+                       ->where('banned', '=', false)
+                       ->where('created_at', '<', now()->sub(1, 'day'))
+                       ->where(function ($query) {
+                               $query->whereNull('detected_language');
+                               $query->orWhereIn('detected_language', $this->getPreferredLanguages());
+                       })
+                       ->inRandomOrder();
+       }
+
+       public function getPreferredLanguages() {
+               $setting = $this->getChatSetting('language');
+               if ($setting) {
+                       return [$setting];
+               }
+               if (!empty($this->languages)) {
+                       return $this->languages;
+               }
+               return ['de'];
+       }
+
+       public function getChatSetting($name, $default = null) {
+               if (array_key_exists($name, $this->chat_settings)) {
+                       return $this->chat_settings[$name];
+               }
+               return $default;
+       }
+
        public function getGuessingLeaderboard() {
                $query = $this->winners()
                        ->selectRaw('(select t2.uname from guessing_winners t2 where t2.uid = guessing_winners.uid order by created_at desc limit 1) as name, sum(score) as score')
+                       ->where('score', '!=', 0)
                        ->groupBy('uid')
                        ->orderBy('score', 'desc')
                        ->limit(10);
@@ -204,6 +240,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);
        }