1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicy do
6 @behaviour Pleroma.Web.ActivityPub.MRF.Policy
9 alias Pleroma.Web.CommonAPI
14 def filter(message) do
15 with follower_nickname <- Config.get([:mrf_follow_bot, :follower_nickname]),
16 %User{actor_type: "Service"} = follower <-
17 User.get_cached_by_nickname(follower_nickname),
18 %{"type" => "Create", "object" => %{"type" => "Note"}} <- message do
19 try_follow(follower, message)
23 "#{__MODULE__} skipped because of missing `:mrf_follow_bot, :follower_nickname` configuration, the :follower_nickname
24 account does not exist, or the account is not correctly configured as a bot."
34 defp try_follow(follower, message) do
35 to = Map.get(message, "to", [])
36 cc = Map.get(message, "cc", [])
37 actor = [message["actor"]]
39 Enum.concat([to, cc, actor])
42 |> User.get_all_by_ap_id()
43 |> Enum.each(fn user ->
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") do
49 "#{__MODULE__}: Follow request from #{follower.nickname} to #{user.nickname}"
52 CommonAPI.follow(follower, user)