mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-23 04:26:57 +00:00
status command
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import Config
|
||||
|
||||
config :plantid_discord_bot,
|
||||
start_time: DateTime.utc_now()
|
||||
|
||||
import_config "#{config_env()}.exs"
|
||||
|
||||
@@ -2,7 +2,6 @@ import Config
|
||||
|
||||
config :plantid_discord_bot,
|
||||
guild_ids: [1_002_507_312_159_797_318],
|
||||
start_time: DateTime.utc_now(),
|
||||
plantnet_api_key: System.get_env("PLANTNET_API_KEY"),
|
||||
plantnet_api_base_url: "https://my-api.plantnet.org/v2",
|
||||
image_folder: "priv/static",
|
||||
|
||||
@@ -2,7 +2,6 @@ import Config
|
||||
|
||||
config :plantid_discord_bot,
|
||||
guild_ids: [],
|
||||
start_time: DateTime.utc_now(),
|
||||
plantnet_api_key: System.get_env("PLANTNET_API_KEY"),
|
||||
plantnet_api_base_url: "https://my-api.plantnet.org/v2",
|
||||
image_folder: "priv/static",
|
||||
|
||||
@@ -2,7 +2,6 @@ import Config
|
||||
|
||||
config :plantid_discord_bot,
|
||||
guild_ids: [1_002_507_312_159_797_318],
|
||||
start_time: DateTime.utc_now(),
|
||||
plantnet_api_key: System.get_env("PLANTNET_API_KEY"),
|
||||
plantnet_api_base_url: "https://my-api.plantnet.org/v2",
|
||||
image_folder: "priv/static",
|
||||
|
||||
@@ -2,7 +2,6 @@ import Config
|
||||
|
||||
config :plantid_discord_bot,
|
||||
guild_ids: [1_002_507_312_159_797_318],
|
||||
start_time: DateTime.utc_now(),
|
||||
plantnet_api_key: System.get_env("PLANTNET_API_KEY"),
|
||||
plantnet_api_base_url: "https://my-api.plantnet.org/v2",
|
||||
image_folder: "priv/static",
|
||||
|
||||
@@ -4,5 +4,8 @@ defmodule PlantIdDiscordBotTest.Mocks.Nostrum.Api do
|
||||
"""
|
||||
|
||||
def create_interaction_response(_interaction, response), do: {:ok, response}
|
||||
def get_application_info(), do: {:ok, %{name: "Test Bot", owner: %{username: "Test User"}}}
|
||||
|
||||
def get_application_information() do
|
||||
{:ok, %{name: "Test Bot", approximate_guild_count: 1, owner: %{username: "Test User"}}}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,13 +10,13 @@ defmodule PlantIdDiscordBot do
|
||||
IO.inspect("Starting PlantIdDiscordBot")
|
||||
|
||||
@global_application_commands [
|
||||
{"servers", "All servers that this bot belongs to, []"},
|
||||
{"invite", "Invite link for this bot, []"},
|
||||
{"source", "Link to the source code for this bot, []"},
|
||||
{"invite", "Invite link for this bot, []"},
|
||||
{"help", "Help information for this bot, []"},
|
||||
{"info", "Information about this bot, []"},
|
||||
{"stats", "Statistics about this bot, []"},
|
||||
{"help", "Help information for this bot, []"},
|
||||
{"status", "API Status, []"},
|
||||
{"servers", "All servers that this bot belongs to, []"},
|
||||
{"id", "ID a plant from up to 5 images, []"}
|
||||
]
|
||||
|
||||
@@ -49,4 +49,20 @@ defmodule PlantIdDiscordBot do
|
||||
def handle_event({:INTERACTION_CREATE, %{data: %{name: "info"}} = interaction, _ws_state}) do
|
||||
Cog.Info.info(interaction)
|
||||
end
|
||||
|
||||
# def handle_event({:INTERACTION_CREATE, %{data: %{name: "stats"}} = interaction, _ws_state}) do
|
||||
# Cog.Info.info(interaction)
|
||||
# end
|
||||
|
||||
def handle_event({:INTERACTION_CREATE, %{data: %{name: "status"}} = interaction, _ws_state}) do
|
||||
Cog.Info.status(interaction)
|
||||
end
|
||||
|
||||
# def handle_event({:INTERACTION_CREATE, %{data: %{name: "servers"}} = interaction, _ws_state}) do
|
||||
# Cog.Info.info(interaction)
|
||||
# end
|
||||
|
||||
# def handle_event({:INTERACTION_CREATE, %{data: %{name: "id"}} = interaction, _ws_state}) do
|
||||
# Cog.Info.info(interaction)
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -3,9 +3,13 @@ defmodule PlantIdDiscordBot.Cog.Info do
|
||||
import Nostrum.Struct.Embed
|
||||
alias PlantIdDiscordBot.Utils
|
||||
|
||||
# reference to Nostrum.Api in non-test environments, reference to mock in test
|
||||
@api Application.compile_env(:plantid_discord_bot, :api)
|
||||
|
||||
# urls
|
||||
@source Application.compile_env(:plantid_discord_bot, :source)
|
||||
@invite Application.compile_env(:plantid_discord_bot, :invite)
|
||||
@plantnet_api_base_url Application.compile_env(:plantid_discord_bot, :plantnet_api_base_url)
|
||||
|
||||
@doc """
|
||||
Sends a link to the source code for this bot.
|
||||
@@ -69,4 +73,20 @@ defmodule PlantIdDiscordBot.Cog.Info do
|
||||
response = %{type: 4, data: %{embeds: [embed]}}
|
||||
@api.create_interaction_response(interaction, response)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Check the status of all relevant APIs.
|
||||
"""
|
||||
def status(interaction) do
|
||||
message =
|
||||
case HTTPoison.get("#{@plantnet_api_base_url}/_status") do
|
||||
{:ok, %{status_code: 200}} ->
|
||||
"PlantNet API is up and running"
|
||||
|
||||
_ ->
|
||||
"PlantNet API is down"
|
||||
end
|
||||
|
||||
@api.create_interaction_response(interaction, %{type: 4, data: %{content: message}})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
defmodule PlantIdDiscordBotTest.Cog.Info do
|
||||
use ExUnit.Case
|
||||
|
||||
test "/info" do
|
||||
{:ok, response} = PlantIdDiscordBot.Cog.Info.info(%{data: %{name: "info"}})
|
||||
[embed] = response[:data][:embeds]
|
||||
assert match?(%Nostrum.Struct.Embed{}, embed)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user