forked from AkkomaGang/akkoma
Try to handle misconfiguration scenarios gracefully
This commit is contained in:
parent
8b81d62227
commit
fba770b3ea
1 changed files with 35 additions and 20 deletions
|
@ -1,16 +1,32 @@
|
||||||
defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicy do
|
defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicy do
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF
|
@behaviour Pleroma.Web.ActivityPub.MRF
|
||||||
|
alias Pleroma.Config
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def filter(message) do
|
def filter(message) do
|
||||||
Task.start(fn ->
|
with follower_nickname <- Config.get([:mrf_follow_bot, :follower_nickname]),
|
||||||
follower_nickname = Pleroma.Config.get([:mrf_follow_bot, :follower_nickname])
|
%User{} = follower <- User.get_cached_by_nickname(follower_nickname),
|
||||||
|
|
||||||
with %User{} = follower <- User.get_cached_by_nickname(follower_nickname),
|
|
||||||
%{"type" => "Create", "object" => %{"type" => "Note"}} <- message do
|
%{"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", [])
|
to = Map.get(message, "to", [])
|
||||||
cc = Map.get(message, "cc", [])
|
cc = Map.get(message, "cc", [])
|
||||||
actor = [message["actor"]]
|
actor = [message["actor"]]
|
||||||
|
@ -28,7 +44,6 @@ def filter(message) do
|
||||||
CommonAPI.follow(follower, user)
|
CommonAPI.follow(follower, user)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
{:ok, message}
|
{:ok, message}
|
||||||
|
|
Loading…
Reference in a new issue