mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-22 20:16:57 +00:00
file server started in supervisor tree
This commit is contained in:
+2
-1
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user