mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-23 12:36:58 +00:00
02372f2076
* added list of tasks to achieve * update deps * update elixir version in CI/CD pipeline * update todo with branch push checks * underscores separation of large numbers * update elixir version and deps * add basic module docs * remove IO.inspect call * check if list is empty rather than traversing list for length * revert empty list code * duration tests * add mime type tests * use logger instread of inspect, remove todos * replace list length check with Enum.empty * replace list length check with !Enum.empty? * numbers readability fix by using underscores on large numbers * iucn parser replaced case with multiclause function and added test * replace map and join with map_join * fix multiple spec issues where map() must be inside a list
43 lines
1.2 KiB
Elixir
43 lines
1.2 KiB
Elixir
defmodule PlantIdDiscordBot.Metrics.Message do
|
|
@moduledoc """
|
|
Metrics messaging.
|
|
"""
|
|
def send() do
|
|
PlantIdDiscordBot.Metrics.requests()
|
|
|> format_message()
|
|
|> do_send_message()
|
|
end
|
|
|
|
defp format_message(data) do
|
|
embeds =
|
|
Enum.map(data, fn {guild_id, metrics} ->
|
|
first_request_at =
|
|
DateTime.truncate(metrics.first_request_at, :second)
|
|
|> DateTime.to_string()
|
|
|
|
last_request_at =
|
|
DateTime.truncate(metrics.last_request_at, :second)
|
|
|> DateTime.to_string()
|
|
|
|
%{
|
|
title: metrics.guild_name,
|
|
fields: [
|
|
%{name: "Guild ID", value: guild_id, inline: true},
|
|
%{name: "First Request At", value: first_request_at, inline: true},
|
|
%{name: "Last Request At", value: last_request_at, inline: true},
|
|
%{name: "Total Requests", value: metrics.total_requests, inline: true}
|
|
]
|
|
}
|
|
end)
|
|
|
|
%{embeds: embeds}
|
|
end
|
|
|
|
defp do_send_message(data) do
|
|
webhook_url = Application.get_env(:plantid_discord_bot, :metrics_webhook_url)
|
|
body = Jason.encode!(data)
|
|
headers = [{"Content-Type", "application/json"}]
|
|
HTTPoison.post!(webhook_url, body, headers)
|
|
end
|
|
end
|