Projects and Diseases placeholder application commands (#17)

* fix module name in backup

* save projects to persistent_term

* retrieve projects on bot startup

* remove commented out code

* register project autocomplete

* placeholder text for project

* placeholder disease command
This commit is contained in:
2025-12-08 08:53:48 +01:00
committed by GitHub
parent 02372f2076
commit 0eddf04678
11 changed files with 182 additions and 27 deletions
+16
View File
@@ -0,0 +1,16 @@
defmodule PlantIdDiscordBot.Cog.Diseases do
@moduledoc """
Functions for using the /diseases application command.
"""
alias PlantIdDiscordBot.PlantNet.Projects
@api Application.compile_env(:plantid_discord_bot, :api)
@doc """
Sends an invite link for this bot.
"""
def diseases(interaction) do
message = "Diseases coming soon."
@api.create_interaction_response(interaction, %{type: 4, data: %{content: message}})
end
end
+71
View File
@@ -0,0 +1,71 @@
defmodule PlantIdDiscordBot.Cog.Projects do
@moduledoc """
Functions for using the /projects application command.
"""
alias PlantIdDiscordBot.PlantNet.Projects
@api Application.compile_env(:plantid_discord_bot, :api)
# ---------------------------------------------------------
# 1. AUTOCOMPLETE HANDLER
# ---------------------------------------------------------
def autocomplete(interaction) do
# Extract what the user is typing (may be nil)
[%{value: user_input}] = interaction.data.options
user_input = user_input || ""
# Fetch your project list
projects = Projects.retrieve_projects()
# Filter based on description
suggestions =
projects
|> Enum.filter(fn p ->
String.contains?(
String.downcase(p["description"]),
String.downcase(user_input)
)
end)
|> Enum.take(25)
|> Enum.map(fn p ->
%{
# what the user sees
name: p["description"],
# what your command receives
value: p["id"]
}
end)
# Respond with autocomplete choices
@api.create_interaction_response(interaction, %{
type: 8,
data: %{choices: suggestions}
})
end
# ---------------------------------------------------------
# 2. FINAL COMMAND EXECUTION
# ---------------------------------------------------------
def projects(interaction) do
# Extract selected project ID
project_id =
interaction.data.options
|> Enum.find(&(&1.name == "project"))
|> then(&(&1 && &1.value))
@api.create_interaction_response(interaction, %{
type: 4,
data: %{
content:
case project_id do
nil ->
"Please choose a project using autocomplete."
id ->
# "You selected project: **#{id}**"
"Identification by project coming soon."
end
}
})
end
end