From b8f7dab8f4b868852667d684687ec506cc661d5f Mon Sep 17 00:00:00 2001 From: Owen Date: Sun, 22 Dec 2024 21:17:21 +0100 Subject: [PATCH] no accepted image type error return --- lib/plantid_discord_bot.ex | 1 - lib/plantid_discord_bot/cogs/plantnet.ex | 39 ++++++++++++++++-------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/plantid_discord_bot.ex b/lib/plantid_discord_bot.ex index 6a15bac..6d86545 100644 --- a/lib/plantid_discord_bot.ex +++ b/lib/plantid_discord_bot.ex @@ -11,7 +11,6 @@ defmodule PlantIdDiscordBot.Consumer do def handle_event({:READY, _data, _ws_state}) do Api.create_global_application_command(@global_application_commands) - # TODO fix, not working Api.update_status(:online, %{name: "Guess the Plant | /help", type: 0}) end diff --git a/lib/plantid_discord_bot/cogs/plantnet.ex b/lib/plantid_discord_bot/cogs/plantnet.ex index 9db33cd..b16096a 100644 --- a/lib/plantid_discord_bot/cogs/plantnet.ex +++ b/lib/plantid_discord_bot/cogs/plantnet.ex @@ -39,21 +39,34 @@ defmodule PlantIdDiscordBot.Cog.PlantNet do attachment_urls = get_attachment_urls(interaction) original_images = get_original_images(attachment_urls) - saved_images = File.download_and_save_files!(attachment_urls) - try do - prepare_images(saved_images) - |> build_query_uri() - |> get_response(interaction, original_images) - rescue - e -> - Logger.error(Exception.format(:error, e, __STACKTRACE__)) + saved_images = + try do + File.download_and_save_files!(attachment_urls) + rescue + e in ArgumentError -> + Api.create_followup_message(interaction.application_id, interaction.token, %{ + content: e.message + }) - Api.create_followup_message(interaction.application_id, interaction.token, %{ - content: "An error occurred. This error has been logged." - }) - after - cleanup_saved_images(saved_images) + nil + end + + if saved_images do + try do + prepare_images(saved_images) + |> build_query_uri() + |> get_response(interaction, original_images) + rescue + e -> + Logger.error(Exception.format(:error, e, __STACKTRACE__)) + + Api.create_followup_message(interaction.application_id, interaction.token, %{ + content: "An error occurred. This error has been logged." + }) + after + cleanup_saved_images(saved_images) + end end end