1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-28 10:52:11 +00:00
mobilizon/lib/mix/tasks/toot.ex

32 lines
751 B
Elixir
Raw Normal View History

2018-11-12 08:05:31 +00:00
defmodule Mix.Tasks.Toot do
@moduledoc """
Creates a bot from a source
"""
use Mix.Task
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Utils
require Logger
@shortdoc "Toot to an user"
def run([from, to, content]) do
Mix.Task.run("app.start")
with %Actor{} = from <- Actors.get_actor_by_name(from),
{:ok, %Actor{} = to} <- ActivityPub.find_or_make_actor_from_nickname(to) do
comment = Utils.make_comment_data(from.url, [to.url], content)
ActivityPub.create(%{
to: [to.url],
actor: from,
object: comment,
local: true
})
else
e -> Logger.error(inspect(e))
end
end
end