mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-23 04:26:57 +00:00
38 lines
1.3 KiB
Elixir
38 lines
1.3 KiB
Elixir
defmodule PlantIdDiscordBot.Consumer do
|
|
@moduledoc """
|
|
A Discord bot that identifies plants from photos of their organs.
|
|
"""
|
|
use Nostrum.Consumer
|
|
alias Nostrum.Api
|
|
alias PlantIdDiscordBot.Cog
|
|
alias PlantIdDiscordBot.Consumer.Commands
|
|
|
|
@global_application_commands Commands.global_application_commands()
|
|
|
|
def handle_event({:READY, _data, _ws_state}) do
|
|
Api.create_global_application_command(@global_application_commands)
|
|
Api.update_status(:online, %{name: "Guess the Plant | /help", type: 0})
|
|
end
|
|
|
|
def handle_event({:INTERACTION_CREATE, %{data: %{name: command}} = interaction, _ws_state}) do
|
|
case command do
|
|
"source" -> Cog.Info.source(interaction)
|
|
"invite" -> Cog.Info.invite(interaction)
|
|
"help" -> Cog.Info.help(interaction)
|
|
"info" -> Cog.Info.info(interaction)
|
|
"stats" -> Cog.Info.stats(interaction)
|
|
"status" -> Cog.Info.status(interaction)
|
|
"servers" -> Cog.Info.servers(interaction)
|
|
"id" -> Cog.PlantNet.id(interaction)
|
|
end
|
|
end
|
|
|
|
def handle_event({:MESSAGE_CREATE, %{attachments: attachments} = message, _ws_state}) do
|
|
if length(attachments) > 0 do
|
|
# deprecated -> Nostrum.Api.Channel.start_typing/1 in v1.0
|
|
Api.start_typing!(message.channel_id)
|
|
Cog.PlantNetMessage.id(message)
|
|
end
|
|
end
|
|
end
|