akkoma/lib/mix/tasks/pleroma/digest.ex

35 lines
1,022 B
Elixir
Raw Normal View History

2019-06-03 23:48:21 +00:00
defmodule Mix.Tasks.Pleroma.Digest do
use Mix.Task
import Mix.Pleroma
2019-06-03 23:48:21 +00:00
@shortdoc "Manages digest emails"
@moduledoc File.read!("docs/administration/CLI_tasks/digest.md")
2019-06-03 23:48:21 +00:00
def run(["test", nickname | opts]) do
2019-06-28 21:52:50 +00:00
Mix.Pleroma.start_pleroma()
2020-07-03 16:18:08 +00:00
Application.ensure_all_started(:timex)
Application.ensure_all_started(:swoosh)
2019-06-03 23:48:21 +00:00
user = Pleroma.User.get_by_nickname(nickname)
last_digest_emailed_at =
with [date] <- opts,
{:ok, datetime} <- Timex.parse(date, "{YYYY}-{0M}-{0D}") do
datetime
else
_ -> user.inserted_at
end
patched_user = %{user | last_digest_emailed_at: last_digest_emailed_at}
2019-08-14 13:46:05 +00:00
with %Swoosh.Email{} = email <- Pleroma.Emails.UserEmail.digest_email(patched_user) do
{:ok, _} = Pleroma.Emails.Mailer.deliver(email)
shell_info("Digest email have been sent to #{nickname} (#{user.email})")
2019-08-14 13:46:05 +00:00
else
_ ->
shell_info("Cound't find any mentions for #{nickname} since #{last_digest_emailed_at}")
2019-08-14 13:46:05 +00:00
end
2019-06-03 23:48:21 +00:00
end
end