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

30 lines
706 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 MobilizonWeb.API.Comments
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
2019-09-22 18:29:13 +02:00
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