ForceBotUnlistedPolicy: simplify code

This commit is contained in:
Alibek Omarov 2020-09-08 01:13:49 +02:00 committed by Gitea
parent d074e54013
commit 95688c90ad

View File

@ -9,15 +9,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy do
require Pleroma.Constants require Pleroma.Constants
defp check_by_actor_type(user) do defp check_by_actor_type(user), do: user.actor_type in ["Application", "Service"]
if user.actor_type in ["Application", "Service"], do: 1.0, else: 0.0 defp check_by_nickname(user), do: Regex.match?(~r/bot@|ebooks@/i, user.nickname)
end
defp check_by_nickname(user) do defp check_if_bot(user), do: check_by_actor_type(user) or check_by_nickname(user)
if Regex.match?(~r/bot@|ebooks@/i, user.nickname), do: 1.0, else: 0.0
end
defp botness_score(user), do: check_by_actor_type(user) + check_by_nickname(user)
@impl true @impl true
def filter( def filter(
@ -30,7 +25,7 @@ def filter(
} = message } = message
) do ) do
user = User.get_cached_by_ap_id(actor) user = User.get_cached_by_ap_id(actor)
isbot = 0.8 < botness_score(user) isbot = check_if_bot(user)
if isbot and Enum.member?(to, Pleroma.Constants.as_public()) do if isbot and Enum.member?(to, Pleroma.Constants.as_public()) do
to = List.delete(to, Pleroma.Constants.as_public()) ++ [user.follower_address] to = List.delete(to, Pleroma.Constants.as_public()) ++ [user.follower_address]