2018-05-30 12:27:21 +00:00
|
|
|
defmodule Mix.Tasks.CreateBot do
|
2018-06-14 16:15:27 +00:00
|
|
|
@moduledoc """
|
|
|
|
Creates a bot from a source
|
|
|
|
"""
|
|
|
|
|
2018-05-30 12:27:21 +00:00
|
|
|
use Mix.Task
|
|
|
|
alias Eventos.Actors
|
|
|
|
alias Eventos.Actors.Bot
|
|
|
|
alias Eventos.Repo
|
2018-07-04 12:29:17 +00:00
|
|
|
alias Eventos.Actors.User
|
2018-05-30 12:27:21 +00:00
|
|
|
import Logger
|
|
|
|
|
|
|
|
@shortdoc "Register user"
|
|
|
|
def run([email, name, summary, type, url]) do
|
|
|
|
Mix.Task.run("app.start")
|
|
|
|
|
2018-07-04 12:29:17 +00:00
|
|
|
with {:ok, %User{} = user} <- Actors.find_by_email(email),
|
2018-05-30 12:27:21 +00:00
|
|
|
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
|