mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-23 04:26:57 +00:00
fix relase environments
This commit is contained in:
@@ -3,6 +3,8 @@ import Config
|
||||
config :plantid_discord_bot,
|
||||
api: Nostrum.Api
|
||||
|
||||
config :plantid_discord_bot, :environment, :dev
|
||||
|
||||
config :logger, :console,
|
||||
format: "$time $metadata[$level] $message\n",
|
||||
level: :debug
|
||||
|
||||
@@ -3,6 +3,8 @@ import Config
|
||||
config :plantid_discord_bot,
|
||||
api: Nostrum.Api
|
||||
|
||||
config :plantid_discord_bot, :environment, :prod
|
||||
|
||||
config :logger,
|
||||
backends: [{PlantIdDiscordBot.DiscordLogger, :discord_logger}]
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ import Config
|
||||
config :plantid_discord_bot,
|
||||
api: PlantIdDiscordBotTest.Mocks.Nostrum.Api
|
||||
|
||||
config :plantid_discord_bot, :environment, :test
|
||||
|
||||
config :logger, :console,
|
||||
format: "$time $metadata[$level] $message\n",
|
||||
level: :debug
|
||||
|
||||
@@ -39,17 +39,14 @@ defmodule PlantIdDiscordBot.Cog.PlantNet do
|
||||
}
|
||||
})
|
||||
|
||||
try 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)
|
||||
|
||||
cleanup_saved_images(saved_images)
|
||||
rescue
|
||||
e ->
|
||||
Logger.error(Exception.format(:error, e, __STACKTRACE__))
|
||||
@@ -57,6 +54,8 @@ defmodule PlantIdDiscordBot.Cog.PlantNet do
|
||||
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
|
||||
|
||||
@@ -70,11 +69,22 @@ defmodule PlantIdDiscordBot.Cog.PlantNet do
|
||||
defp get_original_images(attachment_urls), do: Enum.join(attachment_urls, "\n")
|
||||
|
||||
defp prepare_images(saved_images) do
|
||||
if Mix.env() in [:test, :dev] do
|
||||
case Application.get_env(:plantid_discord_bot, :environment) do
|
||||
:test ->
|
||||
PlantIdDiscordBotTest.Mocks.PlantNet.Images.images()
|
||||
else
|
||||
|
||||
:dev ->
|
||||
PlantIdDiscordBotTest.Mocks.PlantNet.Images.images()
|
||||
|
||||
_ ->
|
||||
Enum.map(saved_images, fn {:ok, filename} -> "#{@fileserver_url}/#{filename}" end)
|
||||
end
|
||||
|
||||
# if Mix.env() in [:test, :dev] do
|
||||
# PlantIdDiscordBotTest.Mocks.PlantNet.Images.images()
|
||||
# else
|
||||
# Enum.map(saved_images, fn {:ok, filename} -> "#{@fileserver_url}/#{filename}" end)
|
||||
# end
|
||||
end
|
||||
|
||||
@spec build_query_uri([String.t()]) :: String.t()
|
||||
|
||||
Reference in New Issue
Block a user