X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FChatLog.php;fp=app%2FModels%2FChatLog.php;h=8a936a82804adee37cc93213fa42cc5e0fde6b47;hb=cce68689529251915af11ade10699ffa74cb6a3b;hp=6f72c352b42ff356123ad3e1bdb29b8d8407e487;hpb=d2e290f1264425f9b01fffd8943717dafe6867a2;p=alttp.git diff --git a/app/Models/ChatLog.php b/app/Models/ChatLog.php index 6f72c35..8a936a8 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 { @@ -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; } @@ -75,6 +77,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;