1 defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicy do
2 @behaviour Pleroma.Web.ActivityPub.MRF
5 alias Pleroma.Web.CommonAPI
10 with follower_nickname <- Config.get([:mrf_follow_bot, :follower_nickname]),
11 %User{actor_type: "Service"} = follower <-
12 User.get_cached_by_nickname(follower_nickname),
13 %{"type" => "Create", "object" => %{"type" => "Note"}} <- message do
14 try_follow(follower, message)
18 "#{__MODULE__} skipped because of missing `:mrf_follow_bot, :follower_nickname` configuration, the :follower_nickname
19 account does not exist, or the account is not correctly configured as a bot."
29 defp try_follow(follower, message) do
31 to = Map.get(message, "to", [])
32 cc = Map.get(message, "cc", [])
33 actor = [message["actor"]]
35 Enum.concat([to, cc, actor])
37 |> User.get_all_by_ap_id()
38 |> Enum.each(fn user ->
39 Logger.info("Checking if #{user.nickname} can be followed")
41 with false <- User.following?(follower, user),
43 false <- (user.bio || "") |> String.downcase() |> String.contains?("nobot") do
44 Logger.info("Following #{user.nickname}")
45 CommonAPI.follow(follower, user)