Skip to content

Bot

The bot is written in Java and uses JDA to communicate with the Discord API.
Additional libraries are also used for other parts, explained below.

Prerequisites

Before contributing to the Bot's code, make sure you cover the following:

  • You have knowledge about the Java Programming language.
  • You have knowledge about JDA and how to use it, especially RestActions.
  • You have knowledge about RethinkDB and its Java-driver.
  • For commands, you have knowledge about JDA-Chewtils.

Commands

If you want to add or modify commands in the bot, you'll need to be aware of a few specific quirks.

The Bot uses JDA-Chewtils, a fork of the origianl JDA-Utilities, to register and handle commands.
This is usually done using a SlashCommand class, but the Bot uses a customized BotCommands class, which extends the original SlashCommand class and overrides specific methods.
This was done to allow more info to be made available, while also pre-processing the command, to not have the 3 seconds limitation Discord gives.

In more laymens terms, the class is handling the initial SlashCommandInteractionEvent, either providing a reply with a loading message, or a replyModal with a Modal.
This allows to process the necessary stuff with a more generous time limit of 15 minutes, while also having access to an InteractionHook instance, Guild instance and Member instance.

An additional ImageAPICommand class exists, which extends the BotCommand class and includes additional fields and methods to set for API requests towards the PurrBot API. This class should be used whenever the command is meant to access one of the API endpoints for random images.

Error Responses

A ErrorReplyMessage class exists, offering static methods to return an Error message for a Slash command event or the InteractionHook. Later should be used within the handle method, as the SlashCommand Event cannot be aknowledged twice.
It is a convenience class to quickly and easily send error messages, either translated or static, to a user using the command.

Creating a command

Commands are defined through a super call, either setting a single name or a name and label.
The former is often used for single commands, while the later is used within child/sub-commands with the label being used for the command itself and the name being used for command translations (Read below).

Translations

Commands support client-side translations, meaning the name and description of the command, subcommand and their options can display a translated text based on the user's Client language.
All translations for commands are found in the command_help section of the language JSON file. They are split up by their internal command name with options being inside an options section.

This means, if you add a command, you'll need to add the following JSON entry to the command_help section:

{
    "command_name": {
        "description": "Description of the Command. Max 100 Characters.",
        "name": "command_name",
        "options": {
            "option1": {
                "description": "Option description. Max 100 Characters.",
                "name": "option1"
            }
        }
    }
}

Discord Limitations

Discord enforces specific limitations on command translations, namely:

  • Command and Option Names need to be alphanummeric with/without underscores and dashes and without spaces.
  • Command and Option descriptions cannot be longer than 100 characters.