X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FChannel.php;fp=app%2FModels%2FChannel.php;h=5c7ae70c0e95ebfec714052becfc28580dc1f354;hb=1d3c8c6a96fc45d839f0e3719baca790059d189f;hp=500f2e33e6f9fb3456694d7dc403159dd7205260;hpb=cf210ddda8ff5336feee10f733b022a72d906238;p=alttp.git diff --git a/app/Models/Channel.php b/app/Models/Channel.php index 500f2e3..5c7ae70 100644 --- a/app/Models/Channel.php +++ b/app/Models/Channel.php @@ -31,6 +31,42 @@ class Channel extends Model { ->first(); } + public function randomOfClass($class) { + $line = $this->queryChatlog() + ->where('classification', '=', $class) + ->first(); + return $line ? $line->text_content : ''; + } + + 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')