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

31 lines
712 B
Elixir
Raw Normal View History

defmodule Mix.Tasks.Mobilizon.Toot 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
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
require Logger
@shortdoc "Toot to an user"
def run([from, text]) do
Mix.Task.run("app.start")
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
{:local_actor, _, _} ->
Mix.shell().error("Failed to toot.\nActor #{from} doesn't exist")
_ ->
Mix.shell().error("Failed to toot.")
end
end
end