The InfoCommand is a highly configurable and dynamic command in our bot, allowing users to fetch information about various entities like players and artisans with different criteria.
The InfoCommand works by interpreting user inputs and executing specific subcommands or dynamic handlers to fetch the required information. The bot provides a default behavior for registered static commands and also handles dynamic queries for more flexibility.
The command can be invoked using the following syntax:
- entity: The type of information to retrieve (e.g.,
player,artisan). - criteria: Additional filtering or specification for the desired result (optional).
Here is a list of currently supported commands:
These commands return all available information for a specific entity.
!info player: Lists all registered players.!info artisan: Lists all available artisans.
These commands include criteria to narrow down the search for more specific results.
- Player Commands:
!info player <archetype>: Fetches players by their archetype (e.g., cleric, ranger).!info player <name>: Fetches detailed information about a player by name.
- Artisan Commands:
!info artisan <artisan-type>: Fetches all artisans of a specific artisan type (e.g., blacksmith, alchemist).
Here are the updated features of the InfoCommand:
-
Static Subcommands for Default Listings
- Supported entities have predefined static subcommands to list all relevant information.
- Example:
!info player: Lists all players.!info artisan: Lists all artisans.
-
Dynamic Criteria Handling
- The bot supports dynamic queries for more specific lookups.
- Dynamic queries rely on a
DynamicValueServiceto fetch or resolve dynamic values based on the provided criteria. - Example:
!info player <archetype>: Fetches players by their archetype.!info player <name>: Fetches a player by name.!info artisan <artisan-type>: Fetches artisans by type.
-
Error Handling
- Graceful error messages when:
- The user provides insufficient or incorrect input.
- Unsupported dynamic criteria are provided.
- Graceful error messages when:
-
Dynamic Value Types The
DynamicValueServiceprocesses multiple types of dynamic values including:archetype: Filters players by their archetype (e.g., healer, DPS).name: Filters players or artisans by their name.artisan-type: Filters artisans by type (e.g., blacksmith, alchemist).
-
Fallback for Unknown Entities
- If the entity is not recognized, the command provides an error message (
Unknown entity). - If specific criteria are invalid, a user-friendly error is displayed.
- If the entity is not recognized, the command provides an error message (
-
Basic List-All Commands
!info player: Shows all registered players.!info artisan: Shows all available artisans.
-
Dynamic Queries
!info player healer: Fetches all players categorized ashealer.!info player JohnDoe: Fetches the player namedJohnDoe.!info artisan blacksmith: Fetches all artisans belonging to theblacksmithartisan type.
-
Empty or Invalid Input
!info: Displays the usage guide (❌ Usage: !info <entity> [criteria]).!info unknownentity: Displays an error (❌ Unknown entity: 'unknownentity'.).!info artisan invalidtype: Displays an error (❌ Invalid artisan lookup for 'invalidtype'. Check input.).
- The command parses the input to extract the
entityand optionalcriteria. - It checks if the
entityhas a static subcommand for a list-all operation (e.g., all players or artisans). - If no static subcommand exists, it attempts to resolve the
entityandcriteriadynamically using theDynamicValueService. - Based on the type of criteria (
archetype,name,artisan-type), specific handler functions are invoked to fetch and display results. - If no valid handler or dynamic value is found, fallback logic or error messages are triggered.
To add new list-all functionality for additional entities:
- Register the
SubCommandin theregisterStaticSubCommands()method. - Provide an implementation for the
SubCommandin the respective handler.
Example:
To expand the range of supported dynamic values:
- Add new types to the
DynamicValueentity. - Handle the new types in the
processDynamicValue()method.
Example:
Modify fallback or error messages in the various methods to tailor the bot's responses to your preferences.
- JDA (Java Discord API): For interacting with Discord servers.
- Spring Framework: For dependency injection and service management.
- Lombok (Optional): For reducing boilerplate in code.
- Expand support for additional entities and criteria.
- Add configurable responses for dynamic queries.
- Add caching for frequently queried dynamic values.
For contributions or issues, feel free to open a pull request or create an issue in the repository.