1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy do
7 @behaviour Pleroma.Web.ActivityPub.MRF
8 @moduledoc "Remove bot posts from federated timeline"
10 require Pleroma.Constants
12 defp check_by_actor_type(user) do
13 if user.actor_type in ["Application", "Service"], do: 1.0, else: 0.0
16 defp check_by_nickname(user) do
17 if Regex.match?(~r/bot@|ebooks@/i, user.nickname), do: 1.0, else: 0.0
20 defp botness_score(user), do: check_by_actor_type(user) + check_by_nickname(user)
32 user = User.get_cached_by_ap_id(actor)
33 isbot = 0.8 < botness_score(user)
35 if isbot and Enum.member?(to, Pleroma.Constants.as_public()) do
36 to = List.delete(to, Pleroma.Constants.as_public()) ++ [user.follower_address]
37 cc = List.delete(cc, user.follower_address) ++ [Pleroma.Constants.as_public()]
48 |> Map.put("object", object)
57 def filter(message), do: {:ok, message}
60 def describe, do: {:ok, %{}}