Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jeff
pleroma
Commits
54ec6d09
Commit
54ec6d09
authored
6 years ago
by
kaniini
Browse files
Options
Downloads
Patches
Plain Diff
mrf: add anti-followbot policy
parent
4983e6e9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex
+57
-0
57 additions, 0 deletions
lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex
with
57 additions
and
0 deletions
lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex
0 → 100644
+
57
−
0
View file @
54ec6d09
# Pleroma: A lightweight social networking server
# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma
.
Web
.
ActivityPub
.
MRF
.
AntiFollowbotPolicy
do
alias
Pleroma
.
User
@behaviour
Pleroma
.
Web
.
ActivityPub
.
MRF
# XXX: this should become User.normalize_by_ap_id() or similar, really.
defp
normalize_by_ap_id
(%{
"id"
=>
id
}),
do
:
User
.
get_cached_by_ap_id
(
id
)
defp
normalize_by_ap_id
(
uri
)
when
is_binary
(
uri
),
do
:
User
.
get_cached_by_ap_id
(
uri
)
defp
normalize_by_ap_id
(
_
),
do
:
nil
defp
score_nickname
(
"followbot@"
<>
_
),
do
:
1.0
defp
score_nickname
(
"federationbot@"
<>
_
),
do
:
1.0
defp
score_nickname
(
"federation_bot@"
<>
_
),
do
:
1.0
defp
score_nickname
(
_
),
do
:
0.0
defp
score_displayname
(
"federation bot"
),
do
:
1.0
defp
score_displayname
(
"federationbot"
),
do
:
1.0
defp
score_displayname
(
"fedibot"
),
do
:
1.0
defp
score_displayname
(
_
),
do
:
0.0
defp
determine_if_followbot
(%
User
{
nickname:
nickname
,
name:
displayname
})
do
nick_score
=
nickname
|>
String
.
downcase
()
|>
score_nickname
()
name_score
=
displayname
|>
String
.
downcase
()
|>
score_displayname
()
nick_score
+
name_score
end
defp
determine_if_followbot
(
_
),
do
:
0.0
@impl
true
def
filter
(%{
"type"
=>
"Follow"
,
"actor"
=>
actor_id
}
=
message
)
do
%
User
{}
=
actor
=
normalize_by_ap_id
(
actor_id
)
score
=
determine_if_followbot
(
actor
)
# TODO: scan biography data for keywords and score it somehow.
if
score
<
0.8
do
{
:ok
,
message
}
else
{
:reject
,
nil
}
end
end
@impl
true
def
filter
(
message
),
do
:
{
:ok
,
message
}
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment