debianize-mobilizon/lib/mix/tasks/mobilizon/toot.ex
Thomas Citharel cc820d6b63
Refactor Core things, including Ecto handling, ActivityPub & Transmogrifier modules
* Data doesn't need anymore to be converted to ActivityStream format to
be saved (this was taken from Pleroma and not at all a good idea here)
* Everything saved when creating an event is inserted into PostgreSQL in
a single transaction
2019-10-31 10:06:11 +01:00

30 lines
706 B
Elixir

defmodule Mix.Tasks.Mobilizon.Toot do
@moduledoc """
Creates a bot from a source.
"""
use Mix.Task
alias MobilizonWeb.API.Comments
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
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