Plant ID Bot
Plant ID Bot is a Discord bot that identifies plants from images of their organs. Invite it here.
Built with
Elixir | Nostrum
The Brief
Allow users to identify plants from images of their organs. These images are to be read from a specified channel, automatically identifying any images that are sent.
This brief has changed over the course of the project. Initially it used slash commands, but at the request of many users, it was changed to identify images automatically.
Method
Using Nostrum, the creation of the Discord bot itself was not challenging. The main challenge came from storing the image that a user had sent to a temporary file server, the URL of which is then sent to the PlantNet API for identification. No matter the outcome, that file is then immediately deleted.
PlantNet returns a JSON response, which is then parsed by the application. This allows the bot to response with the plant identified, and links for more information.
The following example is taken from the bot’s documentation:
iex> response = ~S({
...> "results": [
...> {
...> "score": 0.87871,
...> "species": {
...> "scientificNameWithoutAuthor": "Prunus cerasifera",
...> "commonNames": ["Cherry plum", "myrobalan", "Cherry Plum", "Purple-leaf Plum"]
...> },
...> "gbif": {"id": "3021730"},
...> "powo": {"id": "729568-1"},
...> "iucn": {"category": "DD"}
...> }
...> ]
...> })
iex> PlantIdDiscordBot.PlantNet.Parser.parse(response)
"My best guess is **Prunus cerasifera** with a confidence of **88%**. Common names include **Cherry plum, myrobalan, Cherry Plum, Purple-leaf Plum**.
[GBIF](<https://www.gbif.org/species/3021730>) | [PFAF](<https://pfaf.org/user/Plant.aspx?LatinName=Prunus+cerasifera>) | [POWO](<https://powo.science.kew.org/taxon/729568-1>)
Threat status: DD"
Learning Opportunities
This project was initially written in Python with Pycord. It worked perfectly fine, but I wanted to create a project in Elixir and decided that this would be a good candidate.
This project allowed me to learn how to create:
- File server
- ETS table
- Agent (instead of a GenServer)
The ETS table was used as a crude request limiter, preventing users from spamming the bot.