Skip to content

Commit

Permalink
Update Autospam, add live filters to block remote activities based on…
Browse files Browse the repository at this point in the history
… comma separated keywords
  • Loading branch information
dansup committed Feb 16, 2024
1 parent bc4d223 commit 40b45b2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/Util/ActivityPub/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,23 @@ public static function statusFirstOrFetch($url, $replyTo = false)
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 {
Expand Down
16 changes: 16 additions & 0 deletions app/Util/ActivityPub/Inbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,22 @@ public function handleAddActivity()
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;
Expand Down
5 changes: 5 additions & 0 deletions config/autospam.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@
'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', ''),
]
];

0 comments on commit 40b45b2

Please sign in to comment.