1 defmodule Pleroma.Web.ActivityPub.MRF.FollowbotPolicy do
2 @behaviour Pleroma.Web.ActivityPub.MRF
6 alias Pleroma.Web.CommonAPI
11 def filter(message) do
12 with follower_nickname <- Config.get([:mrf_follow_bot, :follower_nickname]),
13 %User{actor_type: "Service"} = follower <-
14 User.get_cached_by_nickname(follower_nickname),
15 %{"type" => "Create", "object" => %{"type" => "Note"}} <- message do
16 try_follow(follower, message)
20 "#{__MODULE__} skipped because of missing `:mrf_follow_bot, :follower_nickname` configuration, the :follower_nickname
21 account does not exist, or the account is not correctly configured as a bot."
31 defp try_follow(follower, message) do
33 to = Map.get(message, "to", [])
34 cc = Map.get(message, "cc", [])
35 actor = [message["actor"]]
37 Enum.concat([to, cc, actor])
40 |> User.get_all_by_ap_id()
41 |> Enum.each(fn user ->
42 since_thirty_days_ago = NaiveDateTime.utc_now() |> NaiveDateTime.add(-(86_400 * 30))
44 with false <- user.local,
45 false <- User.following?(follower, user),
46 false <- User.locked?(user),
47 false <- (user.bio || "") |> String.downcase() |> String.contains?("nobot"),
49 Activity.follow_requests_outstanding_since?(follower, user, since_thirty_days_ago) do
51 "#{__MODULE__}: Follow request from #{follower.nickname} to #{user.nickname}"
54 CommonAPI.follow(follower, user)