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,
|
config :plantid_discord_bot,
|
||||||
api: Nostrum.Api
|
api: Nostrum.Api
|
||||||
|
|
||||||
|
config :plantid_discord_bot, :environment, :dev
|
||||||
|
|
||||||
config :logger, :console,
|
config :logger, :console,
|
||||||
format: "$time $metadata[$level] $message\n",
|
format: "$time $metadata[$level] $message\n",
|
||||||
level: :debug
|
level: :debug
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import Config
|
|||||||
config :plantid_discord_bot,
|
config :plantid_discord_bot,
|
||||||
api: Nostrum.Api
|
api: Nostrum.Api
|
||||||
|
|
||||||
|
config :plantid_discord_bot, :environment, :prod
|
||||||
|
|
||||||
config :logger,
|
config :logger,
|
||||||
backends: [{PlantIdDiscordBot.DiscordLogger, :discord_logger}]
|
backends: [{PlantIdDiscordBot.DiscordLogger, :discord_logger}]
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import Config
|
|||||||
config :plantid_discord_bot,
|
config :plantid_discord_bot,
|
||||||
api: PlantIdDiscordBotTest.Mocks.Nostrum.Api
|
api: PlantIdDiscordBotTest.Mocks.Nostrum.Api
|
||||||
|
|
||||||
|
config :plantid_discord_bot, :environment, :test
|
||||||
|
|
||||||
config :logger, :console,
|
config :logger, :console,
|
||||||
format: "$time $metadata[$level] $message\n",
|
format: "$time $metadata[$level] $message\n",
|
||||||
level: :debug
|
level: :debug
|
||||||
|
|||||||
@@ -39,17 +39,14 @@ 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
|
try do
|
||||||
attachment_urls = get_attachment_urls(interaction)
|
|
||||||
original_images = get_original_images(attachment_urls)
|
|
||||||
|
|
||||||
saved_images = File.download_and_save_files!(attachment_urls)
|
|
||||||
|
|
||||||
prepare_images(saved_images)
|
prepare_images(saved_images)
|
||||||
|> build_query_uri()
|
|> build_query_uri()
|
||||||
|> get_response(interaction, original_images)
|
|> get_response(interaction, original_images)
|
||||||
|
|
||||||
cleanup_saved_images(saved_images)
|
|
||||||
rescue
|
rescue
|
||||||
e ->
|
e ->
|
||||||
Logger.error(Exception.format(:error, e, __STACKTRACE__))
|
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, %{
|
Api.create_followup_message(interaction.application_id, interaction.token, %{
|
||||||
content: "An error occurred. This error has been logged."
|
content: "An error occurred. This error has been logged."
|
||||||
})
|
})
|
||||||
|
after
|
||||||
|
cleanup_saved_images(saved_images)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -70,11 +69,22 @@ defmodule PlantIdDiscordBot.Cog.PlantNet do
|
|||||||
defp get_original_images(attachment_urls), do: Enum.join(attachment_urls, "\n")
|
defp get_original_images(attachment_urls), do: Enum.join(attachment_urls, "\n")
|
||||||
|
|
||||||
defp prepare_images(saved_images) do
|
defp prepare_images(saved_images) do
|
||||||
if Mix.env() in [:test, :dev] do
|
case Application.get_env(:plantid_discord_bot, :environment) do
|
||||||
PlantIdDiscordBotTest.Mocks.PlantNet.Images.images()
|
:test ->
|
||||||
else
|
PlantIdDiscordBotTest.Mocks.PlantNet.Images.images()
|
||||||
Enum.map(saved_images, fn {:ok, filename} -> "#{@fileserver_url}/#{filename}" end)
|
|
||||||
|
:dev ->
|
||||||
|
PlantIdDiscordBotTest.Mocks.PlantNet.Images.images()
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
Enum.map(saved_images, fn {:ok, filename} -> "#{@fileserver_url}/#{filename}" end)
|
||||||
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
|
end
|
||||||
|
|
||||||
@spec build_query_uri([String.t()]) :: String.t()
|
@spec build_query_uri([String.t()]) :: String.t()
|
||||||
|
|||||||
Reference in New Issue
Block a user