2019-01-03 11:34:31 +01:00
|
|
|
defmodule Mix.Tasks.Mobilizon.Toot do
|
|
|
|
@moduledoc """
|
2019-09-22 16:26:23 +02:00
|
|
|
Creates a bot from a source.
|
2019-01-03 11:34:31 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
use Mix.Task
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2019-10-25 17:43:37 +02:00
|
|
|
alias Mobilizon.Actors
|
|
|
|
alias Mobilizon.Actors.Actor
|
2019-09-22 18:29:13 +02:00
|
|
|
|
2020-01-26 21:11:16 +01:00
|
|
|
alias Mobilizon.GraphQL.API.Comments
|
|
|
|
|
2019-01-03 11:34:31 +01:00
|
|
|
require Logger
|
|
|
|
|
|
|
|
@shortdoc "Toot to an user"
|
2019-10-25 17:43:37 +02:00
|
|
|
def run([from, text]) do
|
2019-01-03 11:34:31 +01:00
|
|
|
Mix.Task.run("app.start")
|
|
|
|
|
2019-10-25 17:43:37 +02:00
|
|
|
with {:local_actor, %Actor{} = actor} <- {:local_actor, Actors.get_local_actor_by_name(from)},
|
|
|
|
{:ok, _, _} <- Comments.create_comment(%{actor: actor, text: text}) do
|
|
|
|
Mix.shell().info("Tooted")
|
|
|
|
else
|
2019-07-30 10:35:29 +02:00
|
|
|
{:local_actor, _, _} ->
|
2019-07-23 18:06:22 +02:00
|
|
|
Mix.shell().error("Failed to toot.\nActor #{from} doesn't exist")
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
Mix.shell().error("Failed to toot.")
|
2019-01-03 11:34:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|