file server started in supervisor tree

This commit is contained in:
Owen
2024-12-15 22:48:47 +01:00
parent 81c95c28b2
commit 1b1fa19fff
8 changed files with 30 additions and 9 deletions
+2 -1
View File
@@ -7,7 +7,8 @@ defmodule PlantIdDiscordBot.Application do
def start(_type, _args) do
children = [
PlantIdDiscordBot.Consumer,
PlantIdDiscordBot.RateLimiter
PlantIdDiscordBot.RateLimiter,
{Plug.Cowboy, scheme: :http, plug: PlantIdDiscordBot.FileServer, options: [port: @port]}
]
opts = [strategy: :one_for_one, name: PlantIdDiscordBot.Supervisor]
-5
View File
@@ -7,8 +7,6 @@ defmodule PlantIdDiscordBot.Consumer do
alias Nostrum.Api
alias PlantIdDiscordBot.Cog
IO.inspect("Starting PlantIdDiscordBot")
@global_application_commands [
{"source", "Link to the source code for this bot, []"},
{"invite", "Invite link for this bot, []"},
@@ -19,8 +17,6 @@ defmodule PlantIdDiscordBot.Consumer do
{"servers", "All servers that this bot belongs to, []"},
{"id", "ID a plant from up to 5 images, []"}
]
# Starts the bot
def handle_event({:READY}) do
# mock function depending on the environment
Api.create_global_application_command(@global_application_commands)
@@ -30,7 +26,6 @@ defmodule PlantIdDiscordBot.Consumer do
Api.create_guild_application_command(1_002_507_312_159_797_318, @global_application_commands)
end
# Handle application commands
def handle_event({:INTERACTION_CREATE, %{data: %{name: command}} = interaction, _ws_state}) do
case command do
"source" -> Cog.Info.source(interaction)
+1 -3
View File
@@ -8,9 +8,7 @@ defmodule PlantIdDiscordBot.Cog.PlantNet do
ID a plant from up to 5 images of organs.
"""
def id(interaction) do
guild_id = interaction.guild_id
case RateLimiter.check_limit(guild_id) do
case RateLimiter.check_limit(interaction.guild_id) do
{:limit_exceeded, value} ->
@api.create_interaction_response(interaction, %{
type: 4,
+12
View File
@@ -0,0 +1,12 @@
defmodule PlantIdDiscordBot.FileServer do
use Plug.Builder
plug(Plug.Logger)
plug(Plug.Static,
at: "/public",
from: "/priv/static"
)
plug(PlantIdDiscordBot.FileServer.Router)
end
@@ -0,0 +1,15 @@
defmodule PlantIdDiscordBot.FileServer.Router do
use Plug.Router
plug(:match)
plug(:dispatch)
def init(options), do: options
get "/health" do
conn
|> send_resp(200, "OK")
end
match(_, do: conn |> send_resp(404, "Not Found"))
end