->first();
}
+ 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() {
+ $min_age = $this->getChatSetting('min_age', 1);
+ $query = ChatLog::where('type', '=', 'chat')
+ ->where('banned', '=', false)
+ ->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() {
+ $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);
$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;
}
return Arr::join($entries, ', ', ' and ');
}
+ public function chat_bot_logs() {
+ return $this->hasMany(ChatBotLog::class);
+ }
+
public function crews() {
return $this->hasMany(ChannelCrew::class);
}