use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
+use LanguageDetector\LanguageDetector;
class ChatLog extends Model {
$this->type = 'system';
return;
}
- if ($this->nick == 'localhorsttv') {
+ if (in_array($this->nick, ['horstiebot', 'localhorsttv'])) {
$this->type = 'self';
return;
}
$this->type = 'dm';
}
$this->text_content = $this->params[1];
+ $this->detectLanguage();
if ($this->scanForSpam()) {
$this->banned = true;
}
$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;