mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-23 04:26:57 +00:00
parsed message paragragh spacing fixes
This commit is contained in:
+3
-11
@@ -82,15 +82,7 @@ defmodule PlantIdDiscordBot.PlantNet.Parser do
|
|||||||
best_result_iucn_category = best_result["iucn"]["category"]
|
best_result_iucn_category = best_result["iucn"]["category"]
|
||||||
score = round(best_result["score"] * 100) |> Integer.to_string()
|
score = round(best_result["score"] * 100) |> Integer.to_string()
|
||||||
|
|
||||||
"""
|
"My best guess is **#{best_guess_name}** with a confidence of **#{score}%**. Common names include **#{Enum.join(best_result["species"]["commonNames"], ", ")}**.\n\n[GBIF](<#{best_result["gbif_url"]}>) | [PFAF](<#{best_result["pfaf_url"]}>) | [POWO](<#{best_result["powo_url"]}>)#{if best_result_iucn_category, do: "\n\nThreat status: #{best_result_iucn_category}"}#{get_alternatives(other_results)}"
|
||||||
My best guess is **#{best_guess_name}** with a confidence of **#{score}%**. Common names include **#{Enum.join(best_result["species"]["commonNames"], ", ")}**.
|
|
||||||
|
|
||||||
[GBIF](<#{best_result["gbif_url"]}>) | [PFAF](<#{best_result["pfaf_url"]}>) | [POWO](<#{best_result["powo_url"]}>)
|
|
||||||
|
|
||||||
#{if best_result_iucn_category, do: "Threat status: #{best_result_iucn_category}", else: ""}
|
|
||||||
|
|
||||||
#{get_alternatives(other_results)}
|
|
||||||
"""
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec generate_gbif_url(map()) :: map()
|
@spec generate_gbif_url(map()) :: map()
|
||||||
@@ -122,13 +114,13 @@ defmodule PlantIdDiscordBot.PlantNet.Parser do
|
|||||||
|
|
||||||
defp get_alternatives(data) do
|
defp get_alternatives(data) do
|
||||||
if length(data) === 0 do
|
if length(data) === 0 do
|
||||||
"No alternatives found."
|
"\n\nNo alternatives found."
|
||||||
else
|
else
|
||||||
alternatives =
|
alternatives =
|
||||||
Enum.map(data, & &1["species"]["scientificNameWithoutAuthor"])
|
Enum.map(data, & &1["species"]["scientificNameWithoutAuthor"])
|
||||||
|> Enum.join(", ")
|
|> Enum.join(", ")
|
||||||
|
|
||||||
"Alternatives include **#{alternatives}**."
|
"\n\nAlternatives include **#{alternatives}**."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -34,4 +34,24 @@ defmodule PlantIdDiscordBotTest.PlantNet.Parser do
|
|||||||
|
|
||||||
refute String.contains?(message, "Threat status: ")
|
refute String.contains?(message, "Threat status: ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "message paragraph spacing" do
|
||||||
|
test "iucn data plus alternatives" do
|
||||||
|
message =
|
||||||
|
PlantNetFixtures.parsed_response_with_urls()
|
||||||
|
|> Parser.generate_response_message()
|
||||||
|
|
||||||
|
assert message ==
|
||||||
|
"My best guess is **Prunus cerasifera** with a confidence of **88%**. Common names include **Cherry plum, myrobalan, Cherry Plum, Purple-leaf Plum**.\n\n[GBIF](<https://www.gbif.org/species/3021730>) | [PFAF](<https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+cerasifera>) | [POWO](<https://powo.science.kew.org/taxon/729568-1>)\n\nThreat status: DD\n\nAlternatives include **Prunus × cistena**."
|
||||||
|
end
|
||||||
|
|
||||||
|
test "no iucn data" do
|
||||||
|
message =
|
||||||
|
PlantNetFixtures.parsed_response_with_urls_no_iucn()
|
||||||
|
|> Parser.generate_response_message()
|
||||||
|
|
||||||
|
assert message ==
|
||||||
|
"My best guess is **Prunus cerasifera** with a confidence of **88%**. Common names include **Cherry plum, myrobalan, Cherry Plum, Purple-leaf Plum**.\n\n[GBIF](<https://www.gbif.org/species/3021730>) | [PFAF](<https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+cerasifera>) | [POWO](<https://powo.science.kew.org/taxon/729568-1>)\n\nAlternatives include **Prunus × cistena**."
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user