From 69192f36ff617d237481c401850171bf79a2f547 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 28 Oct 2018 19:47:56 +0000 Subject: [PATCH] mix tasks: add new task to unsubscribe all users from, and then ban a remote user (e.g. followbots) --- lib/mix/tasks/unsubscribe_user.ex | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/mix/tasks/unsubscribe_user.ex diff --git a/lib/mix/tasks/unsubscribe_user.ex b/lib/mix/tasks/unsubscribe_user.ex new file mode 100644 index 000000000..bb72634b6 --- /dev/null +++ b/lib/mix/tasks/unsubscribe_user.ex @@ -0,0 +1,32 @@ +defmodule Mix.Tasks.UnsubscribeUser do + use Mix.Task + alias Pleroma.{User, Repo} + require Logger + + @shortdoc "Unsubscribe all users from a target and then deactivate them" + def run([nickname]) do + Mix.Task.run("app.start") + + with %User{} = user <- User.get_by_nickname(nickname) do + Logger.info("Deactivating #{user.nickname}") + User.deactivate(user) + + {:ok, friends} = User.get_friends(user) + + Enum.each(friends, fn friend -> + user = Repo.get(User, user.id) + + Logger.info("Unsubscribing #{friend.nickname} from #{user.nickname}") + User.unfollow(user, friend) + end) + + :timer.sleep(500) + + user = Repo.get(User, user.id) + + if length(user.following) == 0 do + Logger.info("Successfully unsubscribed all followers from #{user.nickname}") + end + end + end +end