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{} = follower <- User.get_cached_by_nickname(follower_nickname),
12 %{"type" => "Create", "object" => %{"type" => "Note"}} <- message do
13 try_follow(follower, message)
17 "#{__MODULE__} skipped because of missing :mrf_follow_bot, :follower_nickname configuration or the account
28 defp try_follow(follower, message) do
30 to = Map.get(message, "to", [])
31 cc = Map.get(message, "cc", [])
32 actor = [message["actor"]]
34 Enum.concat([to, cc, actor])
36 |> User.get_all_by_ap_id()
37 |> Enum.each(fn user ->
38 Logger.info("Checking if #{user.nickname} can be followed")
40 with false <- User.following?(follower, user),
42 false <- (user.bio || "") |> String.downcase() |> String.contains?("nobot") do
43 Logger.info("Following #{user.nickname}")
44 CommonAPI.follow(follower, user)