Update Autospam, add live filters to block remote activities based on comma separated keywords

This commit is contained in:
Daniel Supernault 2024-02-16 02:15:39 -07:00
parent bc4d223714
commit 40b45b2a11
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1
3 changed files with 38 additions and 0 deletions

View File

@ -315,6 +315,23 @@ class Helpers {
return; return;
} }
if(config('autospam.live_filters.enabled')) {
$filters = config('autospam.live_filters.filters');
if(!empty($filters) && isset($res['content']) && !empty($res['content']) && strlen($filters) > 3) {
$filters = array_map('trim', explode(',', $filters));
$content = $res['content'];
foreach($filters as $filter) {
$filter = trim($filter);
if(!$filter || !strlen($filter)) {
continue;
}
if(str_contains($content, $filter)) {
return;
}
}
}
}
if(isset($res['object'])) { if(isset($res['object'])) {
$activity = $res; $activity = $res;
} else { } else {

View File

@ -197,6 +197,22 @@ class Inbox
public function handleCreateActivity() public function handleCreateActivity()
{ {
$activity = $this->payload['object']; $activity = $this->payload['object'];
if(config('autospam.live_filters.enabled')) {
$filters = config('autospam.live_filters.filters');
if(!empty($filters) && isset($activity['content']) && !empty($activity['content']) && strlen($filters) > 3) {
$filters = array_map('trim', explode(',', $filters));
$content = $activity['content'];
foreach($filters as $filter) {
$filter = trim($filter);
if(!$filter || !strlen($filter)) {
continue;
}
if(str_contains($content, $filter)) {
return;
}
}
}
}
$actor = $this->actorFirstOrCreate($this->payload['actor']); $actor = $this->actorFirstOrCreate($this->payload['actor']);
if(!$actor || $actor->domain == null) { if(!$actor || $actor->domain == null) {
return; return;

View File

@ -33,5 +33,10 @@ return [
'nlp' => [ 'nlp' => [
'enabled' => false, 'enabled' => false,
'spam_sample_limit' => env('PF_AUTOSPAM_NLP_SPAM_SAMPLE_LIMIT', 200), 'spam_sample_limit' => env('PF_AUTOSPAM_NLP_SPAM_SAMPLE_LIMIT', 200),
],
'live_filters' => [
'enabled' => env('PF_AUTOSPAM_LIVE_FILTERS_ENABLED', false),
'filters' => env('PF_AUTOSPAM_LIVE_FILTERS_CSV', ''),
] ]
]; ];