Commit 3d3618a9 authored by Peter van der meulen's avatar Peter van der meulen

Don't send reports when there are no lights

parent ecfcf9a1
......@@ -46,7 +46,11 @@ defmodule AuroraBot.Report.ForecastReport do
def run! do
report = new!()
ToStore.forecast!(report)
send_slack_message(report)
case Enum.count(report.next_events) do
0 -> :ok
_ -> send_slack_message(report)
end
end
defp send_slack_message(report) do
......@@ -55,36 +59,19 @@ defmodule AuroraBot.Report.ForecastReport do
"\nThe values used in this report are in the KP standard. You can read" <>
" more about that here: \n> `https://bit.ly/more-about-kp`",
[
Map.merge(
%{
"title" => "Aurora Events",
"pretext" => "Next expected auroral events:",
"title_link" => "https://aurora.picodevelopment.nl"
},
attachment_fields(report)
)
%{
"title" => "Aurora Events",
"pretext" => "Next expected auroral events:",
"color" => "good",
"fields" => attachment_fields(report),
"title_link" => "https://aurora.picodevelopment.nl"
}
]
)
end
defp attachment_fields(report) do
case Enum.count(report.next_events) do
0 ->
%{
"color" => "danger",
"fields" => [
%{
"title" => "Nope",
"value" => "No Aurora's are expected in the next few days",
"short" => true
}
]
}
_ ->
fields = Enum.map(report.next_events, fn event -> create_event_field(event) end)
%{"color" => "good", "fields" => fields}
end
Enum.map(report.next_events, fn event -> create_event_field(event) end)
end
defp create_event_field(event) do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment