New generate config task from Pleroma upstream & move tasks namespace
Little fixes and tests Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
30
lib/mix/tasks/mobilizon/create_bot.ex
Normal file
30
lib/mix/tasks/mobilizon/create_bot.ex
Normal file
@@ -0,0 +1,30 @@
|
||||
defmodule Mix.Tasks.Mobilizon.CreateBot do
|
||||
@moduledoc """
|
||||
Creates a bot from a source
|
||||
"""
|
||||
|
||||
use Mix.Task
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Bot
|
||||
alias Mobilizon.Actors.User
|
||||
require Logger
|
||||
|
||||
@shortdoc "Register user"
|
||||
def run([email, name, summary, type, url]) do
|
||||
Mix.Task.run("app.start")
|
||||
|
||||
with {:ok, %User{} = user} <- Actors.get_user_by_email(email, true),
|
||||
actor <- Actors.register_bot_account(%{name: name, summary: summary}),
|
||||
{:ok, %Bot{} = bot} <-
|
||||
Actors.create_bot(%{
|
||||
"type" => type,
|
||||
"source" => url,
|
||||
"actor_id" => actor.id,
|
||||
"user_id" => user.id
|
||||
}) do
|
||||
bot
|
||||
else
|
||||
e -> Logger.error(inspect(e))
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user