Update autospam config, use config_cache

This commit is contained in:
Daniel Supernault 2024-03-12 06:20:26 -06:00
parent da0e0ffabf
commit a76cb5f4f8
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
3 changed files with 65 additions and 60 deletions

View file

@ -183,7 +183,7 @@ class StatusEntityLexer implements ShouldQueue
'photo:video:album',
];
if (config_cache('pixelfed.bouncer.enabled')) {
if ((bool) config_cache('pixelfed.bouncer.enabled')) {
Bouncer::get($status);
}

View file

@ -2,22 +2,26 @@
namespace App\Services;
use App\Util\Lexer\Classifier;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use App\Util\Lexer\Classifier;
class AutospamService
{
const CHCKD_CACHE_KEY = 'pf:services:autospam:nlp:checked';
const MODEL_CACHE_KEY = 'pf:services:autospam:nlp:model-cache';
const MODEL_FILE_PATH = 'nlp/active-training-data.json';
const MODEL_SPAM_PATH = 'nlp/spam.json';
const MODEL_HAM_PATH = 'nlp/ham.json';
public static function check($text)
{
if (! $text || strlen($text) == 0) {
false;
}
if (! self::active()) {
return null;
@ -25,13 +29,14 @@ class AutospamService
$model = self::getCachedModel();
$classifier = new Classifier;
$classifier->import($model['documents'], $model['words']);
return $classifier->most($text) === 'spam';
}
public static function eligible()
{
return Cache::remember(self::CHCKD_CACHE_KEY, 86400, function () {
if(!config_cache('pixelfed.bouncer.enabled') || !config('autospam.enabled')) {
if (! (bool) config_cache('pixelfed.bouncer.enabled') || ! (bool) config_cache('autospam.enabled')) {
return false;
}

View file

@ -815,7 +815,7 @@
<tr>
<td><span class="badge badge-primary">PIXELFED</span></td>
<td><strong>PF_BOUNCER_ENABLED</strong></td>
<td><span>{{config_cache('pixelfed.bouncer.enabled') ? '✅ true' : '❌ false' }}</span></td>
<td><span>{{(bool) config_cache('pixelfed.bouncer.enabled') ? '✅ true' : '❌ false' }}</span></td>
</tr>
<tr>
<td><span class="badge badge-primary">PIXELFED</span></td>