tests: fix up nodeinfo tests
[akkoma] / lib / pleroma / web / activity_pub / mrf / anti_followbot_policy.ex
index 7c6ad582ae9ab6e652d4224931d6451eed461407..ad2d9bf5411b83cc1c5886afc63175134ee958eb 100644 (file)
@@ -5,6 +5,8 @@
 defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do
   alias Pleroma.User
 
+  @moduledoc "Prevent followbots from following with a bit of heuristic"
+
   @behaviour Pleroma.Web.ActivityPub.MRF
 
   # XXX: this should become User.normalize_by_ap_id() or similar, really.
@@ -23,15 +25,21 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do
   defp score_displayname(_), do: 0.0
 
   defp determine_if_followbot(%User{nickname: nickname, name: displayname}) do
+    # nickname will always be a binary string because it's generated by Pleroma.
     nick_score =
       nickname
       |> String.downcase()
       |> score_nickname()
 
+    # displayname will either be a binary string or nil, if a displayname isn't set.
     name_score =
-      displayname
-      |> String.downcase()
-      |> score_displayname()
+      if is_binary(displayname) do
+        displayname
+        |> String.downcase()
+        |> score_displayname()
+      else
+        0.0
+      end
 
     nick_score + name_score
   end
@@ -54,4 +62,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do
 
   @impl true
   def filter(message), do: {:ok, message}
+
+  @impl true
+  def describe(), do: {:ok, %{}}
 end