X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FChatLog.php;h=ae05be631deed3221f6b645f4fcfcb82da8048f9;hb=c130314b819122a9223130277f283584917e58cd;hp=aa4e7aeef913185a1120043b2e8fcfbf66c9e201;hpb=e8eb106aa5adab6dd992390cb3836589e4163e72;p=alttp.git diff --git a/app/Models/ChatLog.php b/app/Models/ChatLog.php index aa4e7ae..ae05be6 100644 --- a/app/Models/ChatLog.php +++ b/app/Models/ChatLog.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use LanguageDetector\LanguageDetector; class ChatLog extends Model { @@ -25,7 +26,7 @@ class ChatLog extends Model { $this->type = 'system'; return; } - if ($this->nick == 'localhorsttv') { + if (in_array($this->nick, ['horstiebot', 'localhorsttv'])) { $this->type = 'self'; return; } @@ -39,6 +40,7 @@ class ChatLog extends Model { $this->type = 'dm'; } $this->text_content = $this->params[1]; + $this->detectLanguage(); if ($this->scanForSpam()) { $this->banned = true; } @@ -53,6 +55,7 @@ class ChatLog extends Model { 'funtoon', 'nightbot', 'pokemoncommunitygame', + 'speedgaming', 'streamelements', 'wizebot', 'zockerstuebchen', @@ -75,6 +78,23 @@ class ChatLog extends Model { $this->channel()->associate($channel); } + protected function detectLanguage() { + $languages = ['de', 'en', 'es', 'fr']; + if (!is_null($this->channel)) { + $languages = array_values($this->channel->languages); + if (!in_array('en', $languages)) { + $languages[] = 'en'; + } + } + $detector = LanguageDetector::detect($this->text_content, $languages); + $scores = $detector->getScores(); + $lang = strval($detector->getLanguage()); + //var_dump($scores, $lang, $this->text_content); + if (is_array($scores) && isset($scores[$lang]) && $scores[$lang] > 0.35) { + $this->detected_language = $lang; + } + } + protected function scanForSpam() { if (substr($this->text_content, 0, 1) == '!') { return true;