Merge pull request #4933 from pixelfed/staging

Autospam Live Filters - block remote activities based on comma separated keywords
This commit is contained in:
daniel 2024-02-16 02:20:23 -07:00 committed by GitHub
commit e1d579b10b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 0 deletions

View File

@ -2,6 +2,9 @@
## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.11.11...dev)
### Features
- Autospam Live Filters - block remote activities based on comma separated keywords ([40b45b2a](https://github.com/pixelfed/pixelfed/commit/40b45b2a))
### Updated
- Update ApiV1Controller, fix network timeline ([0faf59e3](https://github.com/pixelfed/pixelfed/commit/0faf59e3))

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', ''),
]
];