mobilizon.chapril.org-mobil.../lib/mix/tasks/mobilizon/create_bot.ex

36 lines
866 B
Elixir
Raw Normal View History

defmodule Mix.Tasks.Mobilizon.CreateBot do
@moduledoc """
2019-09-22 16:26:23 +02:00
Creates a bot from a source.
"""
use Mix.Task
2019-09-22 16:26:23 +02:00
alias Mobilizon.{Actors, Users}
alias Mobilizon.Actors.Bot
alias Mobilizon.Users.User
import Mix.Tasks.Mobilizon.Common
2019-09-22 16:26:23 +02:00
require Logger
@shortdoc "Create bot"
@spec run(list(String.t())) :: Bot.t() | :ok
def run([email, name, summary, type, url]) do
start_mobilizon()
with {:ok, %User{} = user} <- Users.get_user_by_email(email, activated: true),
{:ok, actor} <- Actors.register_bot(%{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
2019-09-22 16:26:23 +02:00
error ->
Logger.error(inspect(error))
end
end
end