Try to handle misconfiguration scenarios gracefully
This commit is contained in:
parent
8b81d62227
commit
fba770b3ea
@ -1,16 +1,32 @@
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicy do
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
require Logger
|
||||
|
||||
@impl true
|
||||
def filter(message) do
|
||||
Task.start(fn ->
|
||||
follower_nickname = Pleroma.Config.get([:mrf_follow_bot, :follower_nickname])
|
||||
|
||||
with %User{} = follower <- User.get_cached_by_nickname(follower_nickname),
|
||||
with follower_nickname <- Config.get([:mrf_follow_bot, :follower_nickname]),
|
||||
%User{} = follower <- User.get_cached_by_nickname(follower_nickname),
|
||||
%{"type" => "Create", "object" => %{"type" => "Note"}} <- message do
|
||||
try_follow(follower, message)
|
||||
else
|
||||
nil ->
|
||||
Logger.warn(
|
||||
"#{__MODULE__} skipped because of missing :mrf_follow_bot, :follower_nickname configuration or the account
|
||||
does not exist."
|
||||
)
|
||||
|
||||
{:ok, message}
|
||||
|
||||
_ ->
|
||||
{:ok, message}
|
||||
end
|
||||
end
|
||||
|
||||
defp try_follow(follower, message) do
|
||||
Task.start(fn ->
|
||||
to = Map.get(message, "to", [])
|
||||
cc = Map.get(message, "cc", [])
|
||||
actor = [message["actor"]]
|
||||
@ -28,7 +44,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicy do
|
||||
CommonAPI.follow(follower, user)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
{:ok, message}
|
||||
|
Loading…
Reference in New Issue
Block a user