1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-21 23:32:39 +00:00

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;
}
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'])) {
$activity = $res;
} else {

View file

@ -197,6 +197,22 @@ class Inbox
public function handleCreateActivity()
{
$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']);
if(!$actor || $actor->domain == null) {
return;

View file

@ -33,5 +33,10 @@ return [
'nlp' => [
'enabled' => false,
'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', ''),
]
];