import($model['documents'], $model['words']); return $classifier->most($text) === 'spam'; } public static function eligible() { return Cache::remember(self::CHCKD_CACHE_KEY, 86400, function () { if (! (bool) config_cache('pixelfed.bouncer.enabled') || ! (bool) config_cache('autospam.enabled')) { return false; } if (! Storage::exists(self::MODEL_SPAM_PATH)) { return false; } if (! Storage::exists(self::MODEL_HAM_PATH)) { return false; } if (! Storage::exists(self::MODEL_FILE_PATH)) { return false; } else { if (Storage::size(self::MODEL_FILE_PATH) < 1000) { return false; } } return true; }); } public static function active() { return config_cache('autospam.nlp.enabled') && self::eligible(); } public static function getCachedModel() { if (! self::active()) { return null; } return Cache::remember(self::MODEL_CACHE_KEY, 86400, function () { $res = Storage::get(self::MODEL_FILE_PATH); if (! $res || empty($res)) { return null; } return json_decode($res, true); }); } }