3595f912d622ab0dd54de666adb7a4ddad553d08
[akkoma] / lib / mix / tasks / pleroma / digest.ex
1 defmodule Mix.Tasks.Pleroma.Digest do
2 use Mix.Task
3 import Mix.Pleroma
4
5 @shortdoc "Manages digest emails"
6 @moduledoc File.read!("docs/administration/CLI_tasks/digest.md")
7
8 def run(["test", nickname | opts]) do
9 Mix.Pleroma.start_pleroma()
10
11 user = Pleroma.User.get_by_nickname(nickname)
12
13 last_digest_emailed_at =
14 with [date] <- opts,
15 {:ok, datetime} <- Timex.parse(date, "{YYYY}-{0M}-{0D}") do
16 datetime
17 else
18 _ -> user.inserted_at
19 end
20
21 patched_user = %{user | last_digest_emailed_at: last_digest_emailed_at}
22
23 with %Swoosh.Email{} = email <- Pleroma.Emails.UserEmail.digest_email(patched_user) do
24 {:ok, _} = Pleroma.Emails.Mailer.deliver(email)
25
26 shell_info("Digest email have been sent to #{nickname} (#{user.email})")
27 else
28 _ ->
29 shell_info("Cound't find any mentions for #{nickname} since #{last_digest_emailed_at}")
30 end
31 end
32 end