mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-23 04:26:57 +00:00
reworked aliases
This commit is contained in:
@@ -4,10 +4,9 @@ defmodule PlantIdDiscordBot.Consumer do
|
|||||||
"""
|
"""
|
||||||
use Nostrum.Consumer
|
use Nostrum.Consumer
|
||||||
alias Nostrum.Api
|
alias Nostrum.Api
|
||||||
alias PlantIdDiscordBot.Cog
|
alias PlantIdDiscordBot.{Cog, Consumer}
|
||||||
alias PlantIdDiscordBot.Consumer.Commands
|
|
||||||
|
|
||||||
@global_application_commands Commands.global_application_commands()
|
@global_application_commands Consumer.Commands.global_application_commands()
|
||||||
|
|
||||||
def handle_event({:READY, _data, _ws_state}) do
|
def handle_event({:READY, _data, _ws_state}) do
|
||||||
Api.create_global_application_command(@global_application_commands)
|
Api.create_global_application_command(@global_application_commands)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ defmodule PlantIdDiscordBot.Cog.PlantNetMessage do
|
|||||||
alias Nostrum.Cache.GuildCache
|
alias Nostrum.Cache.GuildCache
|
||||||
alias PlantIdDiscordBot.Metrics
|
alias PlantIdDiscordBot.Metrics
|
||||||
|
|
||||||
|
# TODO reintroduce mocks
|
||||||
# @api Application.compile_env(:plantid_discord_bot, :api)
|
# @api Application.compile_env(:plantid_discord_bot, :api)
|
||||||
@plantnet_api_base_url Application.compile_env(:plantid_discord_bot, :plantnet_api_base_url)
|
@plantnet_api_base_url Application.compile_env(:plantid_discord_bot, :plantnet_api_base_url)
|
||||||
@max_results Application.compile_env(:plantid_discord_bot, :max_results)
|
@max_results Application.compile_env(:plantid_discord_bot, :max_results)
|
||||||
@@ -34,11 +35,14 @@ defmodule PlantIdDiscordBot.Cog.PlantNetMessage do
|
|||||||
|> Enum.map(fn attachment -> attachment.url end)
|
|> Enum.map(fn attachment -> attachment.url end)
|
||||||
|> File.download_and_save_files!()
|
|> File.download_and_save_files!()
|
||||||
rescue
|
rescue
|
||||||
|
# TODO add guild id and name into error
|
||||||
|
# TODO test by raising error
|
||||||
e in ArgumentError ->
|
e in ArgumentError ->
|
||||||
Api.create_message(message.channel_id, content: e.message)
|
Api.create_message(message.channel_id, content: e.message)
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO improve composition
|
||||||
if saved_images do
|
if saved_images do
|
||||||
try do
|
try do
|
||||||
prepare_images(saved_images)
|
prepare_images(saved_images)
|
||||||
@@ -72,6 +76,8 @@ defmodule PlantIdDiscordBot.Cog.PlantNetMessage do
|
|||||||
|
|
||||||
defp get_response(query_uri, message) do
|
defp get_response(query_uri, message) do
|
||||||
guild_id = message.guild_id
|
guild_id = message.guild_id
|
||||||
|
|
||||||
|
# TODO move into its own function
|
||||||
{:ok, %{name: guild_name}} = GuildCache.get(guild_id)
|
{:ok, %{name: guild_name}} = GuildCache.get(guild_id)
|
||||||
|
|
||||||
case HTTPoison.get(query_uri) do
|
case HTTPoison.get(query_uri) do
|
||||||
|
|||||||
Reference in New Issue
Block a user